摘要:序本文主要介紹下的的超時參數(shù)。超時參數(shù)相當(dāng)于設(shè)置全局的等待,在定位元素時,對所有元素設(shè)置超時時間,超出了設(shè)置時間則拋出異常。超過這個時間則拋出異常。默認(rèn)為,即永不超時。
序
本文主要介紹下selenium的webdriver的超時參數(shù)。
超時參數(shù)selenium-api-2.53.1-sources.jar!/org/openqa/selenium/WebDriver.java
/** * An interface for managing timeout behavior for WebDriver instances. */ interface Timeouts { /** * Specifies the amount of time the driver should wait when searching for an element if it is * not immediately present. *implicitlyWait* When searching for a single element, the driver should poll the page until the element has * been found, or this timeout expires before throwing a {@link NoSuchElementException}. When * searching for multiple elements, the driver should poll the page until at least one element * has been found or this timeout has expired. *
* Increasing the implicit wait timeout should be used judiciously as it will have an adverse * effect on test run time, especially when used with slower location strategies like XPath. * * @param time The amount of time to wait. * @param unit The unit of measure for {@code time}. * @return A self reference. */ Timeouts implicitlyWait(long time, TimeUnit unit); /** * Sets the amount of time to wait for an asynchronous script to finish execution before * throwing an error. If the timeout is negative, then the script will be allowed to run * indefinitely. * * @param time The timeout value. * @param unit The unit of time. * @return A self reference. * @see JavascriptExecutor#executeAsyncScript(String, Object...) */ Timeouts setScriptTimeout(long time, TimeUnit unit); /** * Sets the amount of time to wait for a page load to complete before throwing an error. * If the timeout is negative, page loads can be indefinite. * * @param time The timeout value. * @param unit The unit of time. * @return A Timeouts interface. */ Timeouts pageLoadTimeout(long time, TimeUnit unit); }
相當(dāng)于設(shè)置全局的等待,在定位元素時,對所有元素設(shè)置超時時間,超出了設(shè)置時間則拋出異常。默認(rèn)為0即不等待。
scriptTimeoutAn implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.
沒有設(shè)置implicitlyWait,則driver.findElement()只會找一遍指定元素,找不到就馬上拋異常
設(shè)置異步腳本執(zhí)行的超時時間,超出則拋異常。
pageLoadTimeoutThe amount of time, in milliseconds, this session should wait for asynchronous scripts to finish executing. If set to 0, then the timeout will not fire until the next event loop after the script is executed. This will give scripts that employ a 0-based setTimeout to finish.
用來設(shè)置頁面完全加載的超時時間,完全加載即頁面全部渲染。超過這個時間則拋出異常。默認(rèn)為-1,即永不超時。
docSets the amount of time to wait for a page load to complete before throwing an error. If the timeout is negative, page loads can be indefinite.
這里是否包含異步腳本都執(zhí)行完成呢,一般onload是指外部資源加載完,而異步腳本執(zhí)行完跟這個應(yīng)該不是一回事。
selenium webdriver(5)—超時設(shè)置
WebDriver: Advanced Usage
webdriver-timeouts
WebDriverWait等設(shè)置等待時間和超時時間
The default value of timeouts on selenium webdriver
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/67831.html
摘要:難在哪里根據(jù)上面的標(biāo)簽需要定位最后一行標(biāo)簽,以下列出了四種方式,定位的方式多樣并不唯一,使用時根據(jù)情況進(jìn)行解析即可。加入每日一練我們使用并指明標(biāo)簽內(nèi)全部文本即可定位。 ...
摘要:耗時代碼運(yùn)行到這句之后觸發(fā)隱式等待,在輪詢檢查后仍然沒有定位到元素,拋出異常。耗時值得一提的是,對于定位不到元素的時候,從耗時方面隱式等待和強(qiáng)制等待沒什么區(qū)別。 ...
摘要:和是中兩個非常重要的類,使用它們提供的方法可以實(shí)現(xiàn)與瀏覽器和頁面元素的各種交互操作。該方法在每個只需要調(diào)用一次等待時間單位為秒設(shè)置一個頁面完全加載完成的超時等待時間等待時間單位為秒設(shè)置腳本執(zhí)行的超時時間,應(yīng)該在拋出錯誤之前等待時間單位為秒 WebDriver 和 WebElement 是 Selenium 中兩個非常重要的類,使用它們提供的方法可以實(shí)現(xiàn)與瀏覽器和頁面元素的各種交互操作。...
摘要:不過動態(tài)渲染的頁面不止這一種。再有淘寶這種頁面,它即使是獲取的數(shù)據(jù),但是其接口含有很多加密參數(shù),我們難以直接找出其規(guī)律,也很難直接分析來抓取。我們用一個實(shí)例來感受一下在這里們依然是先打開知乎頁面,然后獲取提問按鈕這個節(jié)點(diǎn),再將其 上一篇文章:Python3網(wǎng)絡(luò)爬蟲實(shí)戰(zhàn)---36、分析Ajax爬取今日頭條街拍美圖下一篇文章:Python3網(wǎng)絡(luò)爬蟲實(shí)戰(zhàn)---38、動態(tài)渲染頁面抓取:Spla...
閱讀 3513·2021-09-22 15:17
閱讀 2873·2021-09-02 15:15
閱讀 1900·2019-08-30 15:54
閱讀 2062·2019-08-30 14:02
閱讀 2600·2019-08-29 16:58
閱讀 3046·2019-08-29 16:08
閱讀 1409·2019-08-26 12:24
閱讀 1710·2019-08-26 10:41