Re: Not able to handle javascript alert from Selenium WebDriver

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Not able to handle javascript alert from Selenium WebDriver

Keerthi Srujana
I am facing a same issue as mentioned below but with Chrome . Any help would be much appreciated.

Thanks,
K

On Thursday, January 12, 2012 at 2:51:41 PM UTC+5:30, Rana Banerjee wrote:
Hi,

I am using Selenium 2.0 with FireFox WebDriver to test a web
application. I am facing some issues while handling JavaScript alerts.

I have done the following to capture the alert for one page.

Page 1
------------------
WebElement userNameElement = driver.findElement(By.xpath("//
input[@name='user_name']"));
userNameElement.sendKeys("");

WebElement element = driver.findElement(By.xpath("//
input[@name='submit']"));
element.click();

String alert = driver.switchTo().alert().getText();
driver.switchTo().alert().dismiss();

I am able to capture alert here.

Page 2
-----------------
WebElement amountElement = driver.findElement(By.xpath("//
input[@id='amount']"));
amountElement.sendKeys("");

WebElement element = driver.findElement(By.xpath("//
input[@name='submit']"));
element.click();

Alert alert = driver.switchTo().alert();
System.out.println("alert :::" + alert.getText());

Strangely, for Page2, the alert is not populated. While debugging, I
found that, the debug control is lost somewhere after I submit the
form. However, in the application to be tested, the alert appears.
Only after I click the alert manually, the debug control comes to
Alert alert = driver.switchTo().alert(); statement. But since I have
clicked on the alert already, the
org.openqa.selenium.NoAlertPresentException is thrown.

The only difference I can see between Page1 and Page2 code, is that
the former has the javascript function inside the JSP page, the latter
has it in an external .js file.

Any help is much appreciated. Also, please let me know if you need any
further information.

Thanks,
Rana

--
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/624c21b6-c9d6-4cfe-a4b4-4181c59b7b63%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Not able to handle javascript alert from Selenium WebDriver

Shawn McCarthy-2
Keerthi You probably want to open a new thread. This one is 6 years old...

On Wednesday, May 23, 2018 at 9:45:24 AM UTC-7, Keerthi Srujana wrote:
I am facing a same issue as mentioned below but with Chrome . Any help would be much appreciated.

Thanks,
K

On Thursday, January 12, 2012 at 2:51:41 PM UTC+5:30, Rana Banerjee wrote:
Hi,

I am using Selenium 2.0 with FireFox WebDriver to test a web
application. I am facing some issues while handling JavaScript alerts.

I have done the following to capture the alert for one page.

Page 1
------------------
WebElement userNameElement = driver.findElement(By.xpath("//
input[@name='user_name']"));
userNameElement.sendKeys("");

WebElement element = driver.findElement(By.xpath("//
input[@name='submit']"));
element.click();

String alert = driver.switchTo().alert().getText();
driver.switchTo().alert().dismiss();

I am able to capture alert here.

Page 2
-----------------
WebElement amountElement = driver.findElement(By.xpath("//
input[@id='amount']"));
amountElement.sendKeys("");

WebElement element = driver.findElement(By.xpath("//
input[@name='submit']"));
element.click();

Alert alert = driver.switchTo().alert();
System.out.println("alert :::" + alert.getText());

Strangely, for Page2, the alert is not populated. While debugging, I
found that, the debug control is lost somewhere after I submit the
form. However, in the application to be tested, the alert appears.
Only after I click the alert manually, the debug control comes to
Alert alert = driver.switchTo().alert(); statement. But since I have
clicked on the alert already, the
org.openqa.selenium.NoAlertPresentException is thrown.

The only difference I can see between Page1 and Page2 code, is that
the former has the javascript function inside the JSP page, the latter
has it in an external .js file.

Any help is much appreciated. Also, please let me know if you need any
further information.

Thanks,
Rana

--
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/f1eca6c8-7f0c-4114-9f66-ea3cb7d7f55c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.