简体   繁体   English

如何使用 Selenium 处理错误“在异步脚本期间检测到页面重新加载”

[英]How to handle the error 'Page reload detected during async script' using Selenium

How to handle the error Page reload detected during async script using Selenium and InternetExplorerDriver?如何使用 Selenium 和 InternetExplorerDriver 处理Page reload detected during async script的错误Page reload detected during async script

Error stack trace:错误堆栈跟踪:

org.openqa.selenium.JavascriptException: Page reload detected during async script
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_221'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.edgechromium: false, ie.edgepath: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ignoreProtectedModeSettings: false, ignoreZoomSetting: false, initialBrowserUrl: http://localhost:24135/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: f8538187-14df-4144-8bd0-605ce398395e
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.executeAsyncScript(RemoteWebDriver.java:506)
    at stepdefinition.Steps.I_selected_the_Client(Steps.java:60)

This error message...这个错误信息...

org.openqa.selenium.JavascriptException: Page reload detected during async script 
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53' 
System info: os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_221' 
Driver info: org.openqa.selenium.ie.InternetExplorerDriver

...implies that the InternetExplorerDriver was unable to interact with the Browsing Context ie InternetExplorer Browser session. ...暗示InternetExplorerDriver无法与浏览上下文(InternetExplorer 浏览器会话)交互。

A bit more details interms of:关于以下方面的更多细节:

  • Selenium binding art ie Protractor / Java / Python / C# . Selenium 绑定艺术,即量角器/ Java / Python / C#
  • Selenium client version. 客户端版本。
  • InternetExplorerDriver version. InternetExplorerDriver版本。
  • Relevant HTML (if applicable).相关的 HTML(如果适用)。

Would have helped us to construct a canonical answer.会帮助我们构建一个规范的答案。

However, if you are using Protractor as per the documentation in Page reload detected during async script , this error implies:但是,如果您按照在异步脚本期间检测到的页面重新加载中的文档使用量角器,则此错误意味着:

There was a navigation or reload event while a command was pending on the browser.当命令在浏览器上挂起时,发生了导航或重新加载事件。 Usually, this is because a click action or navigation resulted in a page load.通常,这是因为单击操作或导航导致页面加载。 Protractor is trying to wait for Angular to become stable, but it's interrupted by the reload.量角器正试图等待 Angular 变得稳定,但它被重新加载打断了。

Solution解决方案

As a solution, you may need to insert a browser.wait condition to make sure the load is complete before continuing.作为解决方案,您可能需要插入browser.wait条件以确保加载完成,然后再继续。

Could you please provide a minimal sample to reproduce the issue?你能提供一个最小的样本来重现这个问题吗? With which code snippet you're running and in which line the error occurs?您正在运行哪个代码片段以及在哪一行发生错误? You could follow the below sample to automate IE using Selenium webdriver in Java:您可以按照以下示例在 Java 中使用 Selenium webdriver 自动化 IE:

import org.openqa.selenium.By;     
import org.openqa.selenium.WebDriver;     
import org.openqa.selenium.ie.InternetExplorerDriver;     
import org.openqa.selenium.WebElement; 

public class new_java_class {              
public static void main(String[] args) {     
  //add the IE web driver path here..     
  System.setProperty("webdriver.ie.driver","your\\path\\to\\IEwebdriver\\IEDriverServer.exe");              
       WebDriver browser = new InternetExplorerDriver();     
       //replace the URL of the web page here..     
       browser.get("http://testsite.login/");                     
       WebElement username = browser.findElement(By.name("uname"));      
       username.sendKeys("test_user");                     
       WebElement password = browser.findElement(By.name("psw"));        
       password.sendKeys("abcd@1234");                     
       WebElement btn = browser.findElement(By.name("signIn"));      
       btn.click();                     
}              
} 

issue got resolved by using the CSS locator instead of AsynScript to perform click action on webelement.通过使用 CSS 定位器而不是 AsynScript 在 webelement 上执行单击操作,问题得到解决。 Thank You谢谢你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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