Selenium Web驱动程序等到页面刷新 [英] selenium web driver wait until page to refresh

查看:96
本文介绍了Selenium Web驱动程序等到页面刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的硒测试用例的代码片段,其中我使用select方法从下拉列表中选择一个值.下一步将单击提交".但是,当我尝试单击提交"按钮时,页面没有刷新(它将刷新同一页面),抛出了

Below is the code snippet of my selenium test case, where i use select method to choose a value from the drop down . And the next step would be clicking on the submit . But by the time i try to click on the submit button the page is not refreshed(which will refresh the same page), throwing

元素不可点击,StaleElementReference异常

element not clickable,StaleElementReference exception

.对我唯一有效的解决方案是thread.sleep().

. The only solution which works for me is thread.sleep().

我尝试了以下所有选项,但没有运气:(

I tried all the below options but had no luck :(

explicit wait()wait.until(Exceptedcontions.visibility)element to be clickable()等在Web上尝试了所有解决方案.

explicit wait(),wait.until(Exceptedcontions.visibility),element to be clickable() etc , tried all the solutions on th web .

在一个测试用例中,我不得不使用thread.sleep() 3-4次,而我有大约100个测试用例,这花费了很多时间.

I had to use thread.sleep() 3-4 times in a test case and i have around 100 test cases which is costing a lot of time .

任何有效的解决方案,在这些解决方案中,Web驱动程序将等到页面完全刷新并且DOM完全加载后,再单击提交"按钮.

Any working solutions where the web driver waits until the page gets completely refreshed and DOM loads completely before clicking on the submit button.

@Test
@Timeout(group = Group.SLOW)
public void testProvider() throws InterruptedException {

    proceedToProvider();
    new Select(driver.findElement(By.id("searchId"))).selectByVisibleText("Search");
    Thread.sleep(2000);
    driver.findElement(By.id("btnSubmit")).click();
    timeSplit("Search submitted");

以下是我使用其他解决方案时看到的错误.

Below is the error i see when i use other solutions.

org.openqa.selenium.WebDriverException:未知错误:元素不是 在点(1289,141)上可点击.其他元素将获得点击: (会话信息:chrome = 53.0.2785.116)(驱动程序信息: chromedriver = 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform = Windows NT 6.1 SP1 x86_64)(警告:服务器未提供任何堆栈跟踪 信息)命令持续时间或超时:168毫秒生成信息: 版本:"2.49.1",修订: '808c23b0963853d375cbe54b90bbd052e2528a54',时间:'2016-01-21 09:37:52'系统信息:主机:"ALAKASIMA01-W7L",IP:"10.145.45.233", os.name:Windows 7",os.arch:"amd64",os.version:"6.1", java.version:"1.8.0_73"驱动程序信息: org.openqa.selenium.remote.RemoteWebDriver功能 [{applicationCacheEnabled = false,rotatable = false, mobileEmulationEnabled = false,chrome = {chromedriverVersion = 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir = C:\ Users \ kasima01 \ AppData \ Local \ Temp \ scoped_dir6628_12218}, takeHeapSnapshot = true,databaseEnabled = false,handlesAlerts = true, hasTouchScreen = false,版本= 53.0.2785.116,平台= XP, browserConnectionEnabled = false,nativeEvents = true, acceptSslCerts = true,locationContextEnabled = true, webStorageEnabled = true,browserName = chrome,takesScreenshot = true, javascriptEnabled = true,cssSelectorsEnabled = true}]会话ID: 8bf0b4cc7efc715015509f4be345d14d

org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (1289, 141). Other element would receive the click: (Session info: chrome=53.0.2785.116) (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 168 milliseconds Build info: version: '2.49.1', revision: '808c23b0963853d375cbe54b90bbd052e2528a54', time: '2016-01-21 09:37:52' System info: host: 'ALAKASIMA01-W7L', ip: '10.145.45.233', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_73' Driver info: org.openqa.selenium.remote.RemoteWebDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=C:\Users\kasima01\AppData\Local\Temp\scoped_dir6628_12218}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=53.0.2785.116, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 8bf0b4cc7efc715015509f4be345d14d

推荐答案

尝试用此方法检查整个页面是否已加载?

Try this will check entire page is loaded?

    static void waitForPageLoad(WebDriver wdriver) {
    WebDriverWait wait = new WebDriverWait(wdriver, 60);

    Predicate<WebDriver> pageLoaded = new Predicate<WebDriver>() {

        @Override
        public boolean apply(WebDriver input) {
            return ((JavascriptExecutor) input).executeScript("return document.readyState").equals("complete");
        }

    };
    wait.until(pageLoaded);
}

希望这对您有用.

这篇关于Selenium Web驱动程序等到页面刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆