当页面首次加载时,webdriver花费很长时间才能找到第一个元素 [英] When the page load for the first time , webdriver takes a long time to find the first element

查看:166
本文介绍了当页面首次加载时,webdriver花费很长时间才能找到第一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我得到一个URL,然后尝试找到或者

  driver.manage()。timeouts()。pageLoadTimeout (90,TimeUnit.SECONDS); 

driver.get(getApplicationURL());

布尔isPresent = driverUtil.waitAndCheckPresent(20,By.xpath(< my xpath>));
.............................................. .........
..................................... ............



public boolean waitAndCheckPresent(int timeout,By by){

try {
WebDriverWait wait = new WebDriverWait(driver,timeout);
WebElement elem = wait.until(ExpectedConditions
.visibilityOfElementLocated(by));
返回true;
} catch(Exception e){
return false;





详细资料:
FF版本: - 17-24
Webdriver: - 2.35.0



我不知道为什么它会持续很长时间才能继续,正如我刚才提到的只有当页面首次加载时才能看到这个页面,这个页面是一个登录页面,在10秒内出现在输入字段中

解决方案

你可以通过等待预期元素的存在(不等待可见性),例如5-8秒,然后发送window.stop()来加速脚本的执行。停止加载更多的元素),而不用等待整个页面加载
,或者在5-8秒之后捕获页面加载的超时异常,然后调用window.stop()



因为如果页面没有采用延迟加载技术(只加载可见元素并在滚动后加载元素的其余元素),它会在返回window.ready状态之前加载每个元素,所以如果元素的ny需要更长的时间来呈现。


I am using selenium webdriver / java for my application testing , I am facing a strange issue.

When I do get of an URL and then try to find or wait for an element , it takes long to execute that nearly 6 minutes.

driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS);

driver.get(getApplicationURL());

Boolean isPresent = driverUtil.waitAndCheckPresent(20,By.xpath(<my xpath>));
.......................................................
 .................................................



      public boolean waitAndCheckPresent(int timeout, By by){

        try {
            WebDriverWait wait = new WebDriverWait(driver, timeout);
            WebElement elem = wait.until(ExpectedConditions
                    .visibilityOfElementLocated(by));
            return true;
        } catch (Exception e) {
            return false;  
        }

    }

Details:- FF version:- 17-24 Webdriver :- 2.35.0

I have no idea why it is hanging for so long before proceeding , as I mentioned I see this only when the page loads for the first time , [ The page which is a login page comes up in 10 secs with the input fields]

解决方案

You can still speedup your script execution by waiting for presence (not waiting for visibility) of expected element for say 5-8 sec and then sending window.stop() JS Script (to stop loading further elements ) without waiting for entire page to load or catching the timeout exception for page load after 5-8 seconds then calling window.stop()

Because if the page not adopted lazy loading technique (loading only visible element and loading rest of element only after scroll) it loads each element before returning window.ready state so it will be slower if any of the element takes longer time to render.

这篇关于当页面首次加载时,webdriver花费很长时间才能找到第一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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