4

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?");
1
  • 1
    i think the question is about the next line in the code which will fill in a value, say '20', in the javascript prompt. Commented Jun 28, 2012 at 9:48

1 Answer 1

10

It's not very thoroughly documented, but:

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

The Alert interface, the switchTo() method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.