Home > Back-end >  Selenium error how to get text in prompt box
Selenium error how to get text in prompt box

Time:04-19

Here is my code shorted

driver.get('http://orteil.dashnet.org/experiments/cookie/')
driver.find_element(By.ID, 'exportSave').click()
info = driver.switch_to.alert

now I get a error Message: unexpected alert open: I've another question Here is a popup example

I want to get the prompt inside the box where we can write using sendKeys method how to do that?

CodePudding user response:

To capture the alert message.

   String s = driver.switch_to.alert();
   s.getText();

To send some data to alert box.

driver.switch_to.alert().sendKeys("Text");

CodePudding user response:

The below is working for me, this is in java I know you can easily change it in python.

   driver.get('http://orteil.dashnet.org/experiments/cookie/');
    
    driver.findElement(By.xpath("(//div[@id='exportSave'])[1]")).click();
    
    String s = driver.switchTo().alert().getText();
    System.out.println(s);
    
    
    driver.switchTo().alert().sendKeys("Text");
  • Related