[英]I am getting error message as “No alert is active” when i run the script using Java in Webdriver
I am getting error message as "No alert is active" when i run the script using Java in Webdriver. 当我在Webdriver中使用Java运行脚本时,我收到错误消息“没有警报处于活动状态”。 This is inconsistent behavior, it gives error sometimes and it does not give error.
这是不一致的行为,有时会出错,也不会出错。 When I didn't this error message, it will fail at some other location.
当我没有收到此错误消息时,它将在其他位置失败。
Note: The script is working perfectly in my machine. 注意:脚本在我的机器中完美运行。
I have changed all the IE 9 settings in the other machine with my machine setting, from then i am getting this error. 我用我的机器设置更改了其他机器中的所有IE 9设置,从那时起我收到此错误。 previous, i use to get the error message as "Modal Dialog Present".
之前,我用来获取错误消息为“模态对话存在”。
Please find the code i have used below: 请找到我在下面使用的代码:
//Entering data in the Account Information section
driver.findElement(By.name(OR.getProperty("AccName_Id"))).clear();
driver.findElement(By.name(OR.getProperty("AccName_Id"))).
sendKeys(AccName+"_"+Randnum);
driver.findElement(By.name(OR.getProperty("AccDBA_ID"))).sendKeys("Kumar_DBA");
driver.findElement(By.id(OR.getProperty("AccTax_ID"))).sendKeys(""+numberToSend);
driver.findElement(By.name(OR.getProperty("AccAddress_ID"))).sendKeys("124 - City
Cross Roads");
driver.findElement(By.id(OR.getProperty("AccZip_ID"))).sendKeys("00501");
new Actions(driver).sendKeys(driver.findElement(By.id(OR.getProperty("AccZip_ID"))),
"").perform();
//Entering data in the Main Contact Information section
driver.findElement(By.name(OR.getProperty("AccFName_ID"))).sendKeys("Kumara");
driver.findElement(By.name(OR.getProperty("AccMName_ID"))).sendKeys("S");
driver.findElement(By.name(OR.getProperty("AccLName_ID"))).sendKeys("Swamy");
driver.findElement(By.id(OR.getProperty("AccOffNo_ID"))).sendKeys("1234567890");
new Actions(driver).sendKeys(driver.findElement(By.id(OR.getProperty("AccOffNo_ID"))),
"").perform();
driver.findElement(By.id(OR.getProperty("AccCellNo_ID"))).sendKeys("0123456789");
new
Actions(driver).sendKeys(driver.findElement(By.id(OR.getProperty("AccCellNo_ID"))),
"").perform();
driver.findElement(By.id(OR.getProperty("AccFaxNo_ID"))).sendKeys("1234567890");
new Actions(driver).sendKeys(driver.findElement(By.id(OR.getProperty("AccFaxNo_ID"))),
"").perform();
driver.findElement(By.name(OR.getProperty("AccEmail_ID"))).sendKeys("abc@abc.com") ;
driver.findElement(By.id(OR.getProperty("save_ID"))).click();
driver.switchTo().alert().accept();
isAlertPresent();
Thread.sleep(15000);
driver.findElement(By.id(OR.getProperty("AccZip_ID"))).sendKeys("79081");
new Actions(driver).sendKeys(driver.findElement(By.id(OR.getProperty("AccZip_ID"))),
"").perform();
Thread.sleep(8000L);
driver.findElement(By.id(OR.getProperty("save_ID"))).click();
driver.switchTo().alert().accept();
isAlertPresent();
Thread.sleep(30000);
Please help me on this issue ASAP. 请尽快帮我解决这个问题。 Help will be appreciated deeply.
帮助将深深感激。
I think your web driver code fired before the alert renders. 我认为您的Web驱动程序代码在警报呈现之前触发。 My suggest is to put
wait for alert
after click action. 我的建议是点击动作后
wait for alert
。
Try this code: 试试这段代码:
//Do some click action to render alert.
//statement to wait for an alert.
WebDriverWait wait = new WebDriverWait(driver,
30);
wait.until(ExpectedConditions.alertIsPresent());
//accepting the alert
driver.switchTo().alert().accept();
The above code will wait for 30 seconds and check the alert presence every 500ms. 上面的代码将等待30秒并每500ms检查一次警报。 If the alert is present then it will terminate the wait and do the next action.
如果警报存在,那么它将终止等待并执行下一个操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.