Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write in a JavaScript prompt message using WebDriver?

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?");
like image 435
Jasmine.Olivra Avatar asked Dec 26 '22 22:12

Jasmine.Olivra


1 Answers

It's not very thoroughly documented, but:

driver.switchTo().alert().sendKeys("Some text");
driver.switchTo().alert().accept();

The Alert interface, the switchTo() method.

like image 141
Petr Janeček Avatar answered May 05 '23 01:05

Petr Janeček