Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium不等待页面加载_Java_Selenium_Selenium Webdriver - Fatal编程技术网

Java Selenium不等待页面加载

Java Selenium不等待页面加载,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我正在用Selenium做一些测试,这些测试必须登录到一个系统。完全登录需要17秒。 系统必须等待它完成,否则整个测试失败 我尝试过很多方法,但都失败了 我尝试的第一个代码是: driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); 当我使用它时,即使我告诉它等待100秒(几乎是2分钟!),我也会在2秒后得到一个超时 org.openqa.selenium.WebDriverException: timeouts Bu

我正在用Selenium做一些测试,这些测试必须登录到一个系统。完全登录需要17秒。 系统必须等待它完成,否则整个测试失败

我尝试过很多方法,但都失败了

我尝试的第一个代码是:

driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
当我使用它时,即使我告诉它等待100秒(几乎是2分钟!),我也会在2秒后得到一个超时

org.openqa.selenium.WebDriverException: timeouts
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'CMTCLX62137', ip: '53.19.227.206', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_31'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\ALEX\AppData\Local\Temp\rust_mozprofile.Z2KJE568nWB8, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, moz:headless=false, platform=ANY, proxy=Proxy(manual, http=localhost), specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=true, browserVersion=56.0, platformVersion=6.1, moz:processID=21116.0, browserName=firefox, javascriptEnabled=true, platformName=windows_nt}]
Session ID: b2dca4a5-623a-4311-ad07-6444785dbcaf
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:150)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:115)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:45)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteTimeouts.implicitlyWait(RemoteWebDriver.java:868)
我尝试过的另一个代码:

new WebDriverWait(driver, 100).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript(
        "return document.readyState").equals("complete"));
使用这个,它不需要等待,我就可以得到一个

org.openqa.selenium.NoSuchElementException: Unable to locate element
我的测试工作的唯一方法是使用Thread.sleep(),但这是一个非常糟糕的选项,因为有时它的加载速度比预期的快,有时它仍然失败,因为它需要超过17秒


是否有其他选项等待页面完全加载?

此处已解决此问题:

无论如何,我通常会等待我需要使用的控件,而不是等到加载整个页面:

wait.until(ExpectedConditions.elementToBeClickable(By
            .id(ConfigData.IDs.buttonLogin)));

我猜是使用了显式等待而不是页面加载的
elementToBeClickable()

WebElement ele= driver.findElement("Locator Value");
WebDriverWait wait=new WebDriverWait(driver, 20); 
wait.until(ExpectedConditions.elementToBeClickable(ele));
ele.click();

Selenium始终等待页面加载完毕。请发布导致错误的所有代码,以便我们进行调查。仍然可以使用此代码获得“org.openqa.selenium.NoSuchElementException:找不到元素:”提示。无论如何,我猜您得到了答案。抱歉,回答错误。这是有效的。谢谢。@IgorÁvila很想知道什么是
ConfigData.IDs
。我在问题的类似行中没有看到任何内容。这只是我用来存储项目中使用的静态值的静态类,所以我不需要在任何ID更改时更新所有代码,而只需要在我的配置类中。但你必须在每个页面上都这样做。全球解决方案将更加清洁