Tab switch issue in puppeteer

I have an error during tab switch in puppeteer:

await page2.waitForSelector('#save');   
await'#save');  //for saving and closing the page
await page2.waitFor(4000);  // !!it will crash if I remove this line!!
const allPages = await browser.pages();
const page1 = await allPages[0];  
await page1.waitFor(5000);// change nothing even if I wait 10 seconds
await page1.waitForSelector("selector")//crash if I delete 3rd line 

When I run this code without the 3rd line, it triggers an error :

error: Error: Protocol error (Runtime.evaluate): Session closed.
Most likely the page has been closed.
at CDPSession.send(c:pathnode_modulespuppeteerlibConnection.js:172:29)
at ExecutionContext.evaluateHandle (c:pathnode_modulespuppeteerlibExecutionContext.js:56:77)
at EventEmitter._document._documentPromise._contextPromise.then (c:pathnode_modulespuppeteerlibFrameManager.js:310:38)

And page2.waitForNavigation does not work for me, it freezes the page.

I wonder why it crashes if I don’t use the function : waitFor(4000) on page2 and if there is a way to automate the wait for not wasting time for nothing

Or maybe I should wait for page2 completely close after click a button?

how to run multiple instances/tabs in a single chromedriver instance?

open chrome driver
given list of known length urls array, open each url in its own tab and click a counter.
In the urls array list the last url has functionality to go to the page and check the final count.

This is to test websockets, that’s why I want to test it in a single instance.

Current solution:
Have subprocess open with a new instance each time, but this is resource intense.
Trying to lower this resource eating by not opening another instance but rather working in the same instance.

Current solution:
Takes a medium time and most resource usage.

               -> open driver -> go to page -> click counter 
               -> open driver -> go to page -> click counter 
get urls[5] -> -> open driver -> go to page -> click counter 
               -> open driver -> go to page -> click counter 
               -> open driver -> go to page -> click counter 

Wrong solution: takes longest time but least resource usage

open driver -> go to page -> click counter -> open tab -> go to page -> click counter -> 

Wanted Solution: (theoretically) should be a little faster if not the same as the current solution, but medium resource usage. (the usage and time cut downs happen because of one less chromedriver instance opening and all tabs processing at the same time.

                              -> open tab -> go to page -> click counter 
                              -> open tab -> go to page -> click counter 
open driver -> get urls[5] -> -> open tab -> go to page -> click counter 
                              -> open tab -> go to page -> click counter 
                              -> open tab -> go to page -> click counter 

So far I have tried implementing this in golang using chromedp, which has hard to read documentation and the library is very unstable.
The other method I have tried is python with chromedriver which is working very well but the issue is of saving as many resources as possible.

thanks a ton for any help toward the right direction!

puppeteer : select a dropdown option based on text in an external function

Because I dont find puppeteer native function for selecting a dropdox option based on innerText, I am tryong to write it by myself

async function setSelectName(page, selector, valText) {
   return await page.evaluate((data) => {

       let options = document.querySelectorAll(data.selector);

       let optionCount = options.length;

       for (let i = 0; i < optionCount; ++i) {
           if (options[i].text === data.valText) {
                document.querySelector(`'${data.selector}'`).value = options[i].value;

   }, {selector, valText})

Unfortunately it does not work, and when i try to display selected options in console it displays me:


Do understand what happens and how to do it?

Selenium Webdriver – Need to enable chrome extension while launching the browser

I am using the below code to get a chrome extension(Browsec VPN) to open and automate specific site that must has to open on VPN – My code is able to launch the browser with extension but the extension is always in disable mode – I need to get it in enable mode. Please help! Thank you

package AutomationTesting;



public class Test1 {

    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
 //WebDriver driver = null; 
 String URL = "";

 System.setProperty("", "C:\New_Selenium\chromedriver_win32\chromedriver.exe");

 ChromeDriver driver = new ChromeDriver();

ChromeOptions options = new ChromeOptions();
 options.addExtensions(new File("C:\New_Selenium\Browsec-VPN-Free-and-Unlimited-VPN_v3.19.4.crx"));
 //DesiredCapabilities capabilities = new DesiredCapabilities();
 //capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(options);





Detect and test Chrome Extension using Puppeteer

Is there a way to test a Chrome extension using Puppeteer? For example can an extension detect that Chrome was launched in “test” mode to provide different UI, check content scripts are working, etc?

Press a keyboard key with selenium – Is it possible?

I’m trying to build an automation that will install a chrome extension.
On my local system (windows 10) all works fine while using Robot class with java.
The problem is – when i try to run this automation on a virtual machine(Amazon EC2, windows server), the Robot class is not working because it doesn’t detect a physical connection of a keyboard.
Is there any other way to do this?
btw – I have to use the keyboard because google install box is not part of the page and selenium wont recognize it.

Is it possible to use Katalon Chrome’s Extension offline?

I’m currently using the Katalon extension for Chrome which allows me to record actions on the browser and then play them, without my interaction or at least the minimum. I realized that when you start recording your actions, the extension will notify you. I installed the extension on my personal laptop and when I tried to use it I realized that it does not record any operation and does not notify them of anything obvious. The problem in question is that on the laptop I try to do these operations offline, something that was fixed when I connected it but because I’m not always online I would need some way (if possible) to use this tool without being connected to the INTERNET.

The browser version is Google Chrome 60.0 and Katalon Recorder (Selenium IDE for Chrome) 2.1.0


puppeteer : use an external function with dom interaction

With puppeteer chrome test dev tool , I want to set and use an external func

 const puppeteer = require('puppeteer');

async function setSelectVal(sel, val) {
    page.evaluate((data) => {
        return document.querySelector(data.sel).value = data.val
    }, {sel, val})

(async () => {
  const browser = await puppeteer.launch({headless: false});
  const page = await browser.newPage();
  await page.goto('url',  {waitUntil: 'load'});
 setSelectVal('select[name=targetname]', 5)

but it triggers an error:

(node:4888) UnhandledPromiseRejectionWarning: Unhandled promise
rejection (rejection id: 1): ReferenceError: page is not defined
(node:4888) [DEP0018] DeprecationWarning: Unhandled promise rejections
are deprecated. In the future, promise rejections that are not handled
will terminate the Node.js process with a non-zero exit code.

it seems i canot use page

Do you know how I should do?