久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何以最短的等待時間加速 Java Selenium 腳本

How to speed up Java Selenium Script,with minimum wait time(如何以最短的等待時間加速 Java Selenium 腳本)
本文介紹了如何以最短的等待時間加速 Java Selenium 腳本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我目前正在開發(fā)一個 java selenium 項目,它通常是一個小腳本,我必須在其中檢查每個元素是否存在,并基于觸發(fā)了一些操作,但我們主要關(guān)心的是完成腳本的持續(xù)時間.

I'm currently working on a java selenium Project, which is usually a small script where I have to check for each element for it's presence and based on that some actions are triggered but our main concern is time duration to finish the script.

基本上,我在腳本中使用了下面的每一個并運行了測試,雖然在每種情況下腳本都在運行,但我發(fā)現(xiàn)腳本執(zhí)行持續(xù)時間的速度幾乎沒有提高.我正在使用等待

Basically I have used each one from below in my script and ran the test, though in each case script was running but I find very little speed improvement in script execution duration.I'm using wait

driver.manage().timeouts().implicitlyWait(10000,TimeUnit.MILLISECONDS);

和它一起

!(driver.findElement(By.xpath("Element Xpath)).isEmpty()) 

driver.findElements(By.xpath("Element Xpath)).size()>0

我知道我可以選擇 CSS 選擇器,但在我的情況下,由于 DOM 樹結(jié)構(gòu),這是不可行的.可以用什么代替

I know I can go for CSS Selectors but in my case that is not feasible due to DOM Tree structure. what can be used instead of

driver.findElements(By.xpath("Element Xpath)).size()>0

這是檢查元素是否存在,并基于此我必須觸發(fā)多個其他操作.

this to check if element is present or not and based on that I have to trigger multiple other actions.

推薦答案

您的方法存在一些問題.

There are a few issues with your approach.

  1. .implicitlyWait() 實際上并不等待.它為驅(qū)動程序?qū)嵗O(shè)置超時,因此您只需設(shè)置一次,而不是每次要等待時都調(diào)用它.

  1. .implicitlyWait() doesn't actually wait. It sets the timeout for the driver instance so you only need to set it once, not call it each time you want to wait.

driver.findElement(...).isEmpty() 不會編譯.也許您的意思是 .findElements()?無論哪種方式, .isEmpty().size() >0 的速度差異可以忽略不計.

driver.findElement(...).isEmpty() won't compile. Maybe you meant .findElements()? Either way, .isEmpty() vs .size() > 0 is going to be a negligible difference in speed.

主要問題是在檢查不存在的東西時啟用了隱式等待……尤其是等待 10 秒.這意味著每次檢查一個元素時,Selenium 都會等待 10 秒,即使它預(yù)計它不存在.

The main problem is that you have an implicit wait enabled when checking for something to NOT be present... especially a 10s wait. That means that each time an element is checked for, Selenium will wait for 10s even if it's expecting it to NOT be there.

關(guān)閉隱式等待(將其設(shè)置為 0)會更好地為您服務(wù),然后檢查您希望不存在的元素是否存在,然后重新打開它.那將是 10s x # 的存在檢查,您希望不存在.根據(jù)您進行的存在檢查次數(shù),這可能會增加很多時間.這樣做的一個缺點是,如果您有一個帶有后臺進程的復(fù)雜頁面,您將需要等待頁面(或頁面的一部分)完成加載,然后再檢查是否存在隱式等待關(guān)閉的元素.

You would be better served by turning off implicit wait (setting it to 0) and then do your existence check for elements you expect not to be there and then turn it back on. That will be 10s x # of existence checks you expect to not be there. Depending on how many existence checks you do, that could add up to a LOT of time. One downside of this, if you have a complex page with background processes, you will need to have a specific wait for the page (or portion of a page) to finish loading before checking for existence of elements with implicit wait off.

旁注... Selenium 貢獻者聲明不應(yīng)使用隱式等待.改用 WebDriverWait 但這是另一回事.

Side note... Selenium contributors have stated that implicit waits shouldn't be used period. Use WebDriverWait instead but that's a whole other discussion.

這篇關(guān)于如何以最短的等待時間加速 Java Selenium 腳本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 国产99在线 | 欧美 | 欧美综合国产精品久久丁香 | 手机在线不卡av | 成人福利网 | 老子午夜影院 | 中文字幕在线观看 | 亚洲欧美网站 | 国产日韩视频在线 | 欧美日韩电影免费观看 | 久久精彩视频 | 欧美黄色免费网站 | 欧美乱做爰xxxⅹ久久久 | 91视频a| 国产三区av | 国产视频福利 | 日本综合在线观看 | 91正在播放 | 九七午夜剧场福利写真 | 欧美精品在线一区二区三区 | 美女久久久久久久 | 电影91久久久 | www.日日夜夜 | 五月婷婷中文 | 精品国产一二三区 | 国产一级网站 | 国内精品伊人久久久久网站 | 91欧美精品成人综合在线观看 | 少妇黄色 | 欧美国产一区二区三区 | 亚洲精品一区二区三区蜜桃久 | 欧美一级二级三级 | 欧美视频在线播放 | 国产成人精品免费 | 亚洲免费婷婷 | 亚洲高清视频一区 | 国产激情在线看 | 久久久久久亚洲精品 | 尤物在线 | 欧美电影免费观看高清 | 91在线精品一区二区 | www.99精品 |