How to Click on "Accept" button with Selenium Webdriver

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to Click on "Accept" button with Selenium Webdriver

amartin
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!!!!!

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Click on "Accept" button with Selenium Webdriver

⇜Krishnan Mahadevan⇝

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/

 

From: <[hidden email]> on behalf of <[hidden email]>
Reply-To: <[hidden email]>
Date: Friday, June 2, 2017 at 12:43 PM
To: Selenium Users <[hidden email]>
Subject: [selenium-users] How to Click on "Accept" button with Selenium Webdriver

 

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!!!!!

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/DA433969-3E1E-4AD0-9C59-52F3460F79AC%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Click on "Accept" button with Selenium Webdriver

amartin
In reply to this post by amartin
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 pop-up, so, like you say, it's impossible to click in "Accept" button, so, I won't do it.

Thanks so much!


El viernes, 2 de junio de 2017, 9:13:12 (UTC+2), [hidden email] escribió:
Hi guys!

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

<a href="https://lh3.googleusercontent.com/-_LYVvXPUseA/WTEOVhBZvgI/AAAAAAAAAF0/RJa6iZP6sy0WhvWBcReQBSA3bALXBVhZwCLcB/s1600/Screenshot_7.jpg" style="margin-left:1em;margin-right:1em" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-_LYVvXPUseA/WTEOVhBZvgI/AAAAAAAAAF0/RJa6iZP6sy0WhvWBcReQBSA3bALXBVhZwCLcB/s1600/Screenshot_7.jpg&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-_LYVvXPUseA/WTEOVhBZvgI/AAAAAAAAAF0/RJa6iZP6sy0WhvWBcReQBSA3bALXBVhZwCLcB/s1600/Screenshot_7.jpg&#39;;return true;">


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!!!!!

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/db953b6f-4837-4710-b05f-4812443caf32%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Click on "Accept" button with Selenium Webdriver

amartin
In reply to this post by amartin
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!



El viernes, 2 de junio de 2017, 9:13:12 (UTC+2), [hidden email] escribió:
Hi guys!

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

<a href="https://lh3.googleusercontent.com/-_LYVvXPUseA/WTEOVhBZvgI/AAAAAAAAAF0/RJa6iZP6sy0WhvWBcReQBSA3bALXBVhZwCLcB/s1600/Screenshot_7.jpg" style="margin-left:1em;margin-right:1em" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-_LYVvXPUseA/WTEOVhBZvgI/AAAAAAAAAF0/RJa6iZP6sy0WhvWBcReQBSA3bALXBVhZwCLcB/s1600/Screenshot_7.jpg&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-_LYVvXPUseA/WTEOVhBZvgI/AAAAAAAAAF0/RJa6iZP6sy0WhvWBcReQBSA3bALXBVhZwCLcB/s1600/Screenshot_7.jpg&#39;;return true;">


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!!!!!

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/68ab7859-7727-4edc-a035-d0f9a7200f73%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Click on "Accept" button with Selenium Webdriver

Akshat Gupta
In reply to this post by amartin
Hi

Use Robot Class to handle this window.

Thanks.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/789f0c9f-4168-4a4e-b01c-b855b097710d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Click on "Accept" button with Selenium Webdriver

amartin
Ok Thanks!!!

El martes, 6 de junio de 2017, 9:08:06 (UTC+2), Akshat Gupta escribió:
Hi

Use Robot Class to handle this window.

Thanks.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/5ddb0551-4a7f-4822-b797-b2467e304e9f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...