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

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

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

問題描述

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

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.

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

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 樹結構,這是不可行的.可以用什么代替

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

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

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() 實際上并不等待.它為驅動程序實例設置超時,因此您只需設置一次,而不是每次要等待時都調用它.

  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 秒,即使它預計它不存在.

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.

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

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 貢獻者聲明不應使用隱式等待.改用 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.

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

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

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
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 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 91av视频 | 第四色影音先锋 | 国产高清免费 | 欧美激情精品久久久久久 | 亚洲成人观看 | 在线播放中文字幕 | 一级看片 | 日韩免费视频一区二区 | 一级黄色片网站 | 国产精品一区二区无线 | 性生活毛片 | 日韩av一区二区在线观看 | 国产大学生情侣呻吟视频 | 欧美亚洲视频在线观看 | 欧美激情精品久久久久久变态 | 一区二区三区电影在线观看 | 精品在线一区 | 日韩视频一级 | 久久久久久蜜桃一区二区 | 一区二区三区高清 | 国产精品99久久久久久人 | 三区在线| 日韩在线精品视频 | av一二三区 | 国产精品久久久久久久7电影 | 免费精品久久久久久中文字幕 | 影音av| 大陆一级毛片免费视频观看 | 成人福利在线观看 | xxxxx黄色片| 玖玖久久 | 成年人在线观看视频 | 蜜桃视频一区二区三区 | av黄色国产 | 免费观看黄色一级片 | 午夜免费在线观看 | 色伊人久久 | 毛片视频网址 | 国产韩国精品一区二区三区 | 自拍偷拍第一页 | 欧美久久一区 |