Webdriver "get" with a popup

1,048 views
Skip to first unread message

Walter Kelt

unread,
Apr 22, 2015, 2:24:56 PM4/22/15
to seleniu...@googlegroups.com
I've run into a situation where I do a webdriver url get, and a security modal confirmation popup appears before the page fully loads.
The "get" is blocking so I can not deal directly with the popup. 

I experience this only with Chrome, and the popup deals with client certs (its asking me to pick one, even though there is only one).

What are my options for dealing with this scenario ?? 

thanks in advance
walter

mikePietsch

unread,
Apr 22, 2015, 2:42:54 PM4/22/15
to seleniu...@googlegroups.com

I’ve got a similar situation where I have to pick a file from the user’s system, and Selenium doesn’t handle that.  You might be able to modify my approach to fit your needs.

My approach is to get the window handle before I perform the click that brings up a dialog for the picking the file.  Then I get selenium to give me the handles and I weed out the one that I already had, so now I know the handle for the new window.  I use Python, and use it to work with the window based on the handle, and have python pick the file and click the submit button, then I let Selenium go back to doing what it needs to do.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/63591daa-c2b2-4fbd-96f1-37f30c1b4c32%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gopa Kishore Mindi

unread,
Apr 23, 2015, 2:44:09 AM4/23/15
to seleniu...@googlegroups.com
Hi Walter,

After you do a webdriver get check the title/url of the page when the popup appears( as the title/url will must change when the pop up appears) or check any unique property of the popup and using java script you can click on the popup.

if (driver.getTitle().contains("Certificate Error")) {

           driver.navigate()
            .to("javaScript:document.getElementById('id of the popup window').click()");
       

       }

or try the below two ways in the if condition to click on the pop up if the first one does not works for you...

((JavascriptExecutor) driver).executeScript("alert('hello world');");

WebElement element = driver.findElement(By.id("gbqfd"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);


Please let me if it does not works for you.


Thanks,

Gopa

Walter Kelt

unread,
Apr 23, 2015, 7:54:44 AM4/23/15
to seleniu...@googlegroups.com
Hi Gopa;

The problem is that the webdriver "GET" instruction does not finish because its invocation creates a client certificate popup. I have no simple way of accessing the popup, to accept it,  because the GET is a blocking instruction. 

For example:

                 // Add the base url to the specific context path being tested
driver.get(this.baseURL + "/oad/console/");
waitForLoad(driver);

The baseURL uses https. 

When "get" is performed, the very first thing that happens is the system asks the user to choose a client cert via a popup. The actual retrieval of the page won't happen until the popup
is dealt with. I can't easily deal with the popup because the "get" is a blocking command.  

Is there a non-blocking "get" command that I don't know about ?? Or, can I use a separate thread to somehow deal with this popup ?? Is there a Chrome Driver version that allows one
to feed in the client certificate to be used for all https accesses ?? 

walter

Sudhansu Sekhar panda

unread,
Apr 23, 2015, 9:57:15 AM4/23/15
to seleniu...@googlegroups.com
Hi Walter,

How manually you are dealing with the popup?

Thanks,

Sudhansu

Walter Kelt

unread,
Apr 23, 2015, 10:26:27 AM4/23/15
to seleniu...@googlegroups.com
Hi Sudhansu;

Manually, I'd use my mouse and click on the popups "OK" button. 

I want to state once again, the firefox does the "right" thing and uses
the client cert that's been loaded into the firefox browser profile. Chrome
behaves different and still asks for the user to OK the only client cert in its
profile. The problem I am experiencing only happens when using Chrome
(because its the only one that provides a popup during the webdriver get
process).

thanks
Walter

Sudhansu Sekhar panda

unread,
Apr 23, 2015, 11:39:01 AM4/23/15
to seleniu...@googlegroups.com
Hi Walter,

I have one idea and Its working for me. We can do the same thing using multi threading concept like below.

Before the get() method use the below function(modify if you get some error) use the below method.

  // Perform threaded Enter keyboard event
   
public static String performThreadedEnterKeyboardEvent() {




 
Runnable r = new Runnable() {


     
public void run() {


 
try {
     
Robot r = new Robot();
      r
.delay(15000);
      r
.keyPress(KeyEvent.VK_ENTER);
      r
.keyRelease(KeyEvent.VK_ENTER);
 
} catch (Exception ex) {
      ex
.printStackTrace();
 
}


     
}
 
};


 
// Wake up the thread and perform the operation
 
Thread t = new Thread(r);
 t
.start();






 
return "Pressed Keyboard Enter key using a different thread";


   
}

The concept of the above method is both the method will work as it uses two different threads. I have put the delay to 15 sec you can decrease or increase as per your wish. Let say after 10 sec the popup is appearing you can make the delay for 10 sec...


Let me know if it does not work for you..

Note: Yes one  important thing if the Enter does not work using the Robot class then please use the Alert handling mechanism in the function it will work for sure.

Thanks,

Sudhansu



On Wednesday, 22 April 2015 23:54:56 UTC+5:30, Walter Kelt wrote:

Sudhansu Sekhar panda

unread,
Apr 23, 2015, 2:15:44 PM4/23/15
to seleniu...@googlegroups.com
Hi Walter,

Did  you try with that approach?

Thank,

Sudhansu

On Wednesday, 22 April 2015 23:54:56 UTC+5:30, Walter Kelt wrote:

Walter Kelt

unread,
Apr 23, 2015, 2:16:02 PM4/23/15
to seleniu...@googlegroups.com
Using a separate thread was something I was hoping to avoid, but since there doesn't seem to be a better option (nonblocking GET, or chrome driver that
can accept a certificate as an argument), I went ahead and scheduled a thread to do the work. Routine is the following.....basically it presses the enter key in X seconds 
(x defined by method arguments). I call the method right before the driver.get, then need to wait a few seconds for the popup.

    private void prepareToPressEnterKeyIfNeeded(int seconds, boolean chrome) {
if (!chrome) { return;}

ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
ScheduledFuture scheduledFuture = scheduledExecutorService.schedule(new Runnable() {
public void run() {
try { 
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
TimeUnit.SECONDS.sleep(1); //press for 1 sec
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException | InterruptedException e) {
logger.error("Prepare to Press Enter Exception",e);
}
}
},
seconds,
TimeUnit.SECONDS);
scheduledExecutorService.shutdown();
}//end method

The mechanism does the job, but seems ugly to me. Once again, it would be nice to have non-blocking GET/POST available.

Sudhansu Sekhar panda

unread,
Apr 23, 2015, 2:41:35 PM4/23/15
to seleniu...@googlegroups.com
Hi Walter,

Yes you are right. For the timing being you can use a separate Thread to overcome the issue.

Thanks,

Sudhansu

On Wednesday, 22 April 2015 23:54:56 UTC+5:30, Walter Kelt wrote:

Musaffir Lp

unread,
Aug 3, 2015, 11:20:17 PM8/3/15
to Selenium Users
Hi Walter ,

Experiencing the same issue 
Is any better solution know to you ? other than using the thread ?

Warm Regards
Musaffir

Walter Kelt

unread,
Aug 4, 2015, 6:29:16 AM8/4/15
to seleniu...@googlegroups.com
To my knowledge there is still no nonblocking "selenium webdriver get" in Java. Using the executive service, we schedule a small robot based method to begin execution in 5 seconds. 
We issue the executive service instruction immediately before the webdriver get.

Sent from my iPad
--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/eDqPiYoJ9-Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

Musaffir Lp

unread,
Sep 1, 2015, 4:34:28 AM9/1/15
to Selenium Users
Hi Walter / Sudhansu,

Using a separate Thread and pressing Enter key after some delay with Robot class, this seems not very stable for me and it do not dismiss the select certificate pop up which comes after the driver.get(URL)

I run my automation on a virtual machine and i do a remote desktop to that machine ..and what i observed is that even though chrome is the only application which is in front and in focus,
when the select certificate pop up appears the Enter key press is not becoming effective on it ..this should be because the 'ok' button in the pop up is not in real focus / or chrome browser it self not got the control ...

just to experiment with it ,i manually clicked some where in the browser window when it just opened and before loading the url,
when i do that ,this operation becomes successful and the select certificate pop up gets dismissed by robot press enter...
i tried to mimic this action with automation it self . i.e on the launched chrome browser ,before loading the url i clicked on its body , but later haven't got the pop up dismiss result ...

have you faced any such behavior 

Warm Regards
Musaffir

wak...@comcast.net

unread,
Sep 1, 2015, 8:42:00 AM9/1/15
to seleniu...@googlegroups.com
Hi Mussafir;

Yes, window focus is critical/necessary when using the Robot class.

I too click or hover  somewhere on the browser using selenium to ensure I have focus
before the robot class is used. This seems to work for me.  Have you tried maximizing
the browser window to consume the entire screen to see if it helps ?

-walter


From: "Musaffir Lp" <musaf...@gmail.com>
To: "Selenium Users" <seleniu...@googlegroups.com>
Sent: Tuesday, September 1, 2015 4:34:28 AM
Subject: Re: [selenium-users] Re: Webdriver "get" with a popup

Musaffir Lp

unread,
Sep 1, 2015, 11:58:02 PM9/1/15
to Selenium Users
Hi Walter,

Thanks for the reply..

This works perfectly ok in my local machine , but when i run the automation on a VM box it do not works ...

I do make a remote desktop to VM and watch it ...hence there is a UI available...

Just to make sure the chrome browser is in control and in focus , i load some dummy url and click on some text box with selenium ,before i actually load or perform driver.get(my actual application url) which gives the select certificate pop up...

but the focus is not gng to the 'ok' button when the select certificate pop appears in the UI i believe , hence robot enter goes in vain :(


Thanks & Warm Regards

wak...@comcast.net

unread,
Sep 2, 2015, 7:52:02 AM9/2/15
to seleniu...@googlegroups.com
Can you rdp to the VM and startup the automation within the VM ?? Does this work ?? It may be that the mere act of RDP'ng into
the VM "changes" what keyboard is being "used", and who is controlling the view frame,  thus causing issues with the Robot class. Are you running a windows server, or win7/8/10 ?? 

Yeah, maintaining "focus" in a VM environment can be pain to deal with. 




From: "Musaffir Lp" <musaf...@gmail.com>
To: "Selenium Users" <seleniu...@googlegroups.com>
Sent: Tuesday, September 1, 2015 11:58:02 PM

Louise

unread,
Nov 18, 2015, 6:08:44 AM11/18/15
to Selenium Users
Thank you, thank you, thank you Walter! This works. I've been desperately trying everything I could find for the last three days, so happy I finally found something :)
Reply all
Reply to author
Forward
0 new messages