简体   繁体   中英

selenium UnhandledalertException on firefox not executing Webdriver Classes

After Autoit script completes login me through windows authenticate my selenium stops working and not executing any command on browser (Firefox)

System

Version: 19.0 Platform:Windows 7 Firefox: 56.0 (64 bit) Selenium: 3.6.0 Testcase

I want to get title of my webpage but unbale to print it as browser not reading any .driver class

public static void main(String[] args) throws IOException {
    System.setProperty("webdriver.gecko.driver", "C:/Users/aamir.fatimi/Downloads/geckodriver-v0.19.0-win64/geckodriver.exe");

WebDriver driver = new FirefoxDriver();
driver.get("http://dbu-export-09/en/Pages/default.aspx");
Runtime.getRuntime().exec("C:\\Users\\aamir.fatimi\\Desktop\\AutoIT\\Autoit.exe");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
String get_Title = driver.getTitle();

System.out.println("Title is" + get_Title);
driver.quit();

EDITED:

You can try to wait for alert to be absent in this way:

(new WebDriverWait(driver, 10))
    .until(ExpectedConditions.not(ExpectedConditions.alertIsPresent()));

right after your Autoit script execution to make sure that WebDriver get's title when Autoit actually is finished. Assuming of course your Autoit script doesn't leave any alerts hanging, in which case you can simply try:

//Snippet from answer of smit9234 - not tested
try {
    Alert alert = driver.switchTo().alert();
    alert.sendKeys(username + Keys.TAB.toString() + password);
    alert.accept();
} catch (Exception e) {
    e.printStackTrace();
}

again, right after (or probably even instead, if the script is supposed to close the alert and just works incorrectly/inconsistently) the script. Or modify Autoit to close alert, and go with option 1.

Expanding on the Kudin's Answer above:

  1. Remove the AutoIT script
  2. Add the following in place of it
 try { Alert alert = driver.switchTo().alert(); alert.sendKeys(yourusername + Keys.TAB.toString()+yourpassword); alert.accept(); } catch (Exception e) { e.printStackTrace(); } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM