Unable to click browser popups in chrome browser

237 views
Skip to first unread message

testingzeal

unread,
May 15, 2013, 7:10:46 PM5/15/13
to webd...@googlegroups.com
driver.switchTo().alert().accept();  is not working in chrome browser.I checked with my dev guy and he says it is a browser pop up.

Any ideas??

Mark Collin

unread,
May 16, 2013, 3:31:23 AM5/16/13
to webd...@googlegroups.com
Selenium can only interact with JavaScript popups, not browser popups.

If you are getting a browser popup I would suggest that your test is probably not doing anything particularly useful (i.e. you are tesing the browsers functionality rather than your websites functionality).


On 16/05/2013 00:10, testingzeal wrote:
driver.switchTo().alert().accept();  is not working in chrome browser.I checked with my dev guy and he says it is a browser pop up.

Any ideas??
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Piotr Szymanski

unread,
May 16, 2013, 6:34:53 AM5/16/13
to webd...@googlegroups.com

Hello,

as Mark said, selenium does not provide support for this kind of popups.

If this is a browser pop up where you have to only press Yes|No|Accept|Cancel etc. you can use robot:
http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html


Thanks,
Piotr


2013/5/16 Mark Collin <mark....@lazeryattack.com>

testingzeal

unread,
May 16, 2013, 10:42:25 PM5/16/13
to webd...@googlegroups.com
I tried this and it doens't work,by the way it is confirm dialog 

 Robot robot = new Robot(); 
 robot.keyPress(KeyEvent.VK_ENTER);


Here is the function where the confirm is =================

function deleteImage2(id)

{

if(confirm('Are you sure you want to delete this image?')) {

document.forms.imageForm2.deleteImageID.value=id;

document.forms.imageForm2.catID.value='3';

document.forms.imageForm2.submit();

}

==== When i record in IDE it shows this line ,but doesn't work when i paste this code in my method,it blows up 
 assertTrue(closeAlertAndGetItsText().matches("^Are you sure you want to delete this image[\\s\\S]$"));

Any help please ???

darrell

unread,
May 17, 2013, 8:23:51 AM5/17/13
to webdriver
Inside the deleteImage2 method, the first if statement has a
javascript confirm() call. This is what is creating the dialog. This
is javascript and Selenium can handle this without any problems.

Somewhere you have a web element which triggers the call to
deleteImage2(). It might be something like clicking a button. the
<BUTTON> tag will have an onclick attribute. Whatever it is that
causes deleteImage2() to be called, you need the code to handle the
event. So lets say the locator for the 'button' is stored in
deleteButtonLocator then your code might look like:

driver.findElement(deleteButtonLocator).click(); // causes the
dialog to appear
Alert a = driver.switchTo().alert(); // switch focus to the dialog
String text = a.getText(); // get the text for the dialog
a.accept(); // click the OK button
// a.dismiss(); // click the Cancel button

If you want to click Cancel, just comment out the a.accept() and
uncomment the a.dismiss().


On May 16, 10:42 pm, testingzeal <jselen...@gmail.com> wrote:
> I tried this and it doens't work,by the way it is confirm dialog
>
>  Robot robot = new Robot();
>  robot.keyPress(KeyEvent.VK_ENTER);
>
> Here is the function where the confirm is =================
>
> function deleteImage2(id)
>
> {
>
> if(confirm('Are you sure you want to delete this image?')) {
>
> document.forms.imageForm2.deleteImageID.value=id;
>
> document.forms.imageForm2.catID.value='3';
>
> document.forms.imageForm2.submit();
>
> }
> }
>
> ==== When i record in IDE it shows this line ,but doesn't work when i paste
> this code in my method,it blows up
>  assertTrue(closeAlertAndGetItsText().matches("^Are you sure you want to
> delete this image[\\s\\S]$"));
>
> Any help please ???
>
>
>
>
>
>
>
> On Thursday, May 16, 2013 4:34:53 AM UTC-6, CVQ PRS wrote:
>
> > Hello,
>
> > as Mark said, selenium does not provide support for this kind of popups.
>
> > If this is a browser pop up where you have to only press
> > Yes|No|Accept|Cancel etc. you can use robot:
> >http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html
>
> > Thanks,
> > Piotr
>
> > 2013/5/16 Mark Collin <mark....@lazeryattack.com <javascript:>>
>
> >>  Selenium can only interact with JavaScript popups, not browser popups.
>
> >> If you are getting a browser popup I would suggest that your test is
> >> probably not doing anything particularly useful (i.e. you are tesing the
> >> browsers functionality rather than your websites functionality).
>
> >> On 16/05/2013 00:10, testingzeal wrote:
>
> >> driver.switchTo().alert().accept();  is not working in chrome browser.I
> >> checked with my dev guy and he says it is a browser pop up.
>
> >>  Any ideas??
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "webdriver" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an
> >> email to webdriver+...@googlegroups.com <javascript:>.
> >> To post to this group, send email to webd...@googlegroups.com<javascript:>
> >> .
> >> Visit this group athttp://groups.google.com/group/webdriver?hl=en.
> >> For more options, visithttps://groups.google.com/groups/opt_out.
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "webdriver" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an
> >> email to webdriver+...@googlegroups.com <javascript:>.
> >> To post to this group, send email to webd...@googlegroups.com<javascript:>
> >> .
> >> Visit this group athttp://groups.google.com/group/webdriver?hl=en.
> >> For more options, visithttps://groups.google.com/groups/opt_out.
Message has been deleted

testingzeal

unread,
May 17, 2013, 11:12:27 AM5/17/13
to webd...@googlegroups.com
Darrell,

this is how the js is called...

<a href=javascript:deleteImage2('2457126');">Delete Photo</a>

I have this line 
driver.findElement(By.linkText("Delete Photo")).click();

This triggers the pop up and driver.swithto.alert.accept is not working...

I am using 2.24 version of selenium and win7 and browser is chrome..

Can you tell me what am I missing?

darrell

unread,
May 19, 2013, 6:56:21 PM5/19/13
to webd...@googlegroups.com
A better description than "not working..." would be helpful. 

    WebElement deleteLink = driver.findElement(By.linkText("Delete Photo"));
    deleteLink.click();
    Alert a = driver.switchTo().alert();
    String text = a.getText();
    a.accept();

This code snippet should work. If it does not you must give better feedback than "not working".

testingzeal

unread,
May 20, 2013, 12:45:00 PM5/20/13
to webd...@googlegroups.com
Sorry...Here is what it is doing...

The alert.accept is working on IE.
But in chrome, clicking on "delete link" triggers the popup and it sits there and doesn't do anything..after a while i am terminating the test

In the debug mode , it is stuck on deleteLink.click() and doesn't move further....until i terminate the test.

darrell

unread,
May 21, 2013, 9:54:50 AM5/21/13
to webd...@googlegroups.com
Not enough information to help. If I worked with you I'd run the application and figure out what information you are missing. "doesn't move further" doesn't tell me anything. For anyone to help you we need more information. If I understand you correctly, you set a breakpoint on the deleteLink.click(), run to breakpoint (debug mode), step over the deleteLink.click(), an alert window pops up and the WebDriver code never returns. If this is correct the DeleteImage2() javascript method is doing something which is blocking the click from working correctly.

On the other hand, if the click is working fine and stepping over the driver.switchTo().alert() is failing, i.e. it never returns, then something is blocking the switchTo().alert() call. You never to figure out what the DeleteImage2() is doing and if it is getting stuck in there. The confirm() call in the DeleteImage2() should be creating an alert and WebDriver is switching to it.

You can debug the javascript as well to see if it is functioning correctly or conflicting with WebDriver. You can try altering your WebDriver code to see if it changes things. Then try to theorize why the change you have to your test would cause whatever happens. If you throw a Thread.sleep in, does it change things? If you check the state of the deleteLink before you click it (it is visible, is it enabled, etc.) does it tell you something which gives you an ah-ha moment?

Post what you are doing to gather more information. If you are using your eyeballs and there isn't enough information, code your script so it gives you more information. This is basic code debugging. Don't treat it as a user would treat it; debug the code.
Reply all
Reply to author
Forward
0 new messages