How to Click on "Accept" button with Selenium Webdriver

503 views
Skip to first unread message

ama...@bufetedemarketing.com

unread,
Jun 2, 2017, 3:13:12 AM6/2/17
to Selenium Users
Hi guys!

I have a problem with a pop-up in Selenium Webdriver. I get the following clicking in the "Export to excel" button:


I've tried to accept this dialog doing the following:

                Alert alert = driver.switchTo().alert();
alert.accept();

But it returns the following error: Exception in thread "main" org.openqa.selenium.NoAlertPresentException: No modal dialog is currently open

It seems not to be an alert dialog, so, I tried too the following:

                ArrayList<String> tabs2 = new ArrayList<String> (driver.getWindowHandles());

driver.switchTo().window(tabs2.get(0));                        // I put "get(0)" because the size is 1 (I don't know why it doesn't count two windows)
driver.findElement(By.linkText("Aceptar")).click();        // I don't know how to identify the name of the button (it's impossible right-button mouse on that dialog

And it returns the following error: Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: Aceptar


Any ideas how could I click "Accept" button of this new window??

Thanks so much!!!!!

Krishnan Mahadevan

unread,
Jun 2, 2017, 3:31:44 AM6/2/17
to seleniu...@googlegroups.com

What you are seeing is NOT a Javascript triggered alert, but is an OS dialog box which cannot be handled by WebDriver. That explains why you see the size as 1 when you query the window handles.

 

You might want to spend sometime reading through this blog post : http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
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/e55df771-19ed-4b59-a5f2-d76afacfafda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

ama...@bufetedemarketing.com

unread,
Jun 2, 2017, 4:09:30 AM6/2/17
to Selenium Users
Ok Thanks!!

I've tried with this code:

        //Store the current window handle
String winHandleBefore = driver.getWindowHandle();
driver.findElement(By.xpath(".//*[@id='xls-export']")).click();
Thread.sleep(5000);
//Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
 driver.switchTo().window(winHandle);
}
//Perform the actions on new window
//Close the new window, if that window no more required
driver.close();
//Switch back to original browser (first window)
driver.switchTo().window(winHandleBefore);

With this code  I only can close the entire webpage (pop-up and parent window), how could I close only the pop-up?

And, like you say, it's impossible to click in "Accept" button, so, I won't do it. But I need to continue the navigation through the web after closing the pop-up...

Any ideas?

Thanks so much!

Akshat Gupta

unread,
Jun 6, 2017, 3:08:06 AM6/6/17
to Selenium Users
Hi

Use Robot Class to handle this window.

Thanks.

ama...@bufetedemarketing.com

unread,
Jun 6, 2017, 3:36:08 AM6/6/17
to Selenium Users
Ok Thanks!!!
Reply all
Reply to author
Forward
0 new messages