-1

I have an online Web Application where there is a product listed which have a View button. On clicking the View button an alert is shown. The Alert have four (4) fields as: Alert Text, An Input Text field, OK button & Cancel button. The Alert text reads as "The Alert Text is :Product is out of Stock ! Please enter your Email Id".

If I Cancel the alert with my Selenium Java code, it works well:

//Switch to the Alert & Dismiss
driver.switchTo().alert().dismiss();

If I simply click OK with my Selenium Java code, it does works well:

//Click on Accept
driver.switchTo().alert().accept();

But if I try to provide my email id in the Input Text field on the Alert,

Thread.sleep(3000);
driver.switchTo().alert().sendKeys("debanjan.selenium@mymail.com");
//driver.switchTo().alert().sendKeys("debanjan");

//Click on Accept
driver.switchTo().alert().accept();

Selenium is showing org.openqa.selenium.WebDriverException as follows:

The Alert Text is :Product is out of Stock ! Please enter your Email Id org.openqa.selenium.WebDriverException: Missing 'value' parameter (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 6 milliseconds

OS Details: 'Windows 8' pro, os.arch: 'amd64', os.version: '6.2',

Java.version: '1.8.0_77'

Driver info: org.openqa.selenium.firefox.FirefoxDriver

Can anyone help me out please?

The weird thing is that: When I try through standalone Selenium Java Class to handle the Alert (i.e. passing the emailID in the Alert Text Box) this piece of code works fine.

driver.switchTo().alert().sendKeys("debanjan.selenium@gmail.com");

But when the same code is implemented through a FRAMEWORK (which I implemented) [Class : PlaceOrder, Method : orderCamera()], the emailID is never written in the Textbox field of the Alert.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • try using Robot to pass value in the alert box if driver.switchTo().alert().sendKeys("debanjan") doesn't work. – shank087 Feb 06 '17 at 09:15

2 Answers2

1

You need to send the email to the specific text field

Alert alert = driver.switchTo().alert();
WebElement inputTextField = driver.findElement(...);
inputTextField.sendKeys("debanjan.selenium@mymail.com");
alert.accept();

And to switch back

driver.switchTo().defaultContent();
Guy
  • 46,488
  • 10
  • 44
  • 88
  • I wanted to tryout this approach but neither with Firebug/Firepath nor with xPathCheeker I am able to find out the xpath of the element (i.e. textbox). Any other suggestion? – undetected Selenium Feb 06 '17 at 14:09
  • @Dev Can you share the website? – Guy Feb 06 '17 at 14:13
  • 1
    @Guy, are you sure that this code might ever work? pop-ups triggered by `alert()`, `prompt()`, `confirm()` are not part of `DOM` and thus there is no possibility to select "elements" from pop-up. – Andersson Feb 10 '17 at 12:21
  • @Andersson The OP didn't mention how the alert is being created, so I thought he/she might check this option. – Guy Feb 10 '17 at 14:11
0

Have you try driver.switchTo().alert().sendKeys()

Roy
  • 65
  • 1
  • 7
  • Yes, I have tried this: <> but it doesn't works for me. – undetected Selenium Feb 06 '17 at 14:03
  • @Dev This solution work for me. Could you help to check if this is a real alert or a modal with alert look. – Roy Feb 08 '17 at 02:27
  • The weird thing is that: When I try through standalone Selenium Java Class to handle the Alert (i.e. passing the emailID in the Alert Text Box) this piece of code works fine. driver.switchTo().alert().sendKeys("debanjan.selenium@gmail.com"); But when the same code is implemented through a FRAMEWORK [Class : PlaceOrder, Method : orderCamera()], the emailID is never written in the Textbox field of the Alert. – undetected Selenium Feb 08 '17 at 04:59