I want to write some text in Javascript Prompt. I tried following code to run javascript prompt. How do I fill a value in the prompt using selenium/webdriver?
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.javascripter.net/faq/prompt.htm#top");
driver.findElement(By.xpath("//input[@value = 'Try it now']")).click();
Alert javascriptprompt = myTestDriver.switchTo().alert();
javascriptprompt.sendKeys("How do I write in a JavaScript prompt message using WebDriver?");
It's not very thoroughly documented, but:
driver.switchTo().alert().sendKeys("Some text");
driver.switchTo().alert().accept();
The Alert
interface, the switchTo()
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With