简体   繁体   English

当我在Webdriver中使用Java运行脚本时,我收到错误消息“没有警报处于活动状态”

[英]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.

相关问题 运行以下Java代码时出现此错误 - I am getting this error when I run the below java code 为什么在 JAVA 中使用扫描仪时出现运行时错误 - Why I am getting a RUNTIME ERROR when using Scanner in JAVA 当我在jmeter中将脚本与Beanshell Sampler一起使用时出现错误,因为无法初始化类 - I am getting error when I am using Beanshell Sampler with script in jmeter as Could not initialize class 当我尝试在 Java 中运行我的套接字程序时,为什么会出现错误? - Why am I getting an error when I try to run my socket program in Java? 运行代码时,我在 Java Derby 数据库中收到此外键错误 - I am getting this foreign key error in Java Derby database when I run the code 为什么我在运行时收到 java.lang.StringIndexOutOfBoundsException 错误? - Why am I getting a java.lang.StringIndexOutOfBoundsException error when I run? 为什么在 Windows 7 上尝试安装 Java SDK 时会收到错误消息? - Why am I getting an error message when trying to install the Java SDK on Windows 7? 为什么在运行应用程序时出现此错误? - Why am I getting this error when I run my app? 当我尝试运行代码时,会出现错误消息 - When i am trying to run the code then an error message is occur 我正在尝试运行我的应用程序,并且收到此错误消息? - i am trying to run my app and i am getting this error message?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM