摘要:序本文主要介紹下的的超時(shí)參數(shù)。超時(shí)參數(shù)相當(dāng)于設(shè)置全局的等待,在定位元素時(shí),對(duì)所有元素設(shè)置超時(shí)時(shí)間,超出了設(shè)置時(shí)間則拋出異常。超過這個(gè)時(shí)間則拋出異常。默認(rèn)為,即永不超時(shí)。
序
本文主要介紹下selenium的webdriver的超時(shí)參數(shù)。
超時(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í),對(duì)所有元素設(shè)置超時(shí)時(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()只會(huì)找一遍指定元素,找不到就馬上拋異常
設(shè)置異步腳本執(zhí)行的超時(shí)時(shí)間,超出則拋異常。
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è)置頁(yè)面完全加載的超時(shí)時(shí)間,完全加載即頁(yè)面全部渲染。超過這個(gè)時(shí)間則拋出異常。默認(rèn)為-1,即永不超時(shí)。
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í)行完跟這個(gè)應(yīng)該不是一回事。
selenium webdriver(5)—超時(shí)設(shè)置
WebDriver: Advanced Usage
webdriver-timeouts
WebDriverWait等設(shè)置等待時(shí)間和超時(shí)時(shí)間
The default value of timeouts on selenium webdriver
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/67831.html
摘要:難在哪里根據(jù)上面的標(biāo)簽需要定位最后一行標(biāo)簽,以下列出了四種方式,定位的方式多樣并不唯一,使用時(shí)根據(jù)情況進(jìn)行解析即可。加入每日一練我們使用并指明標(biāo)簽內(nèi)全部文本即可定位。 ...
摘要:耗時(shí)代碼運(yùn)行到這句之后觸發(fā)隱式等待,在輪詢檢查后仍然沒有定位到元素,拋出異常。耗時(shí)值得一提的是,對(duì)于定位不到元素的時(shí)候,從耗時(shí)方面隱式等待和強(qiáng)制等待沒什么區(qū)別。 ...
摘要:和是中兩個(gè)非常重要的類,使用它們提供的方法可以實(shí)現(xiàn)與瀏覽器和頁(yè)面元素的各種交互操作。該方法在每個(gè)只需要調(diào)用一次等待時(shí)間單位為秒設(shè)置一個(gè)頁(yè)面完全加載完成的超時(shí)等待時(shí)間等待時(shí)間單位為秒設(shè)置腳本執(zhí)行的超時(shí)時(shí)間,應(yīng)該在拋出錯(cuò)誤之前等待時(shí)間單位為秒 WebDriver 和 WebElement 是 Selenium 中兩個(gè)非常重要的類,使用它們提供的方法可以實(shí)現(xiàn)與瀏覽器和頁(yè)面元素的各種交互操作。...
摘要:不過動(dòng)態(tài)渲染的頁(yè)面不止這一種。再有淘寶這種頁(yè)面,它即使是獲取的數(shù)據(jù),但是其接口含有很多加密參數(shù),我們難以直接找出其規(guī)律,也很難直接分析來抓取。我們用一個(gè)實(shí)例來感受一下在這里們依然是先打開知乎頁(yè)面,然后獲取提問按鈕這個(gè)節(jié)點(diǎn),再將其 上一篇文章:Python3網(wǎng)絡(luò)爬蟲實(shí)戰(zhàn)---36、分析Ajax爬取今日頭條街拍美圖下一篇文章:Python3網(wǎng)絡(luò)爬蟲實(shí)戰(zhàn)---38、動(dòng)態(tài)渲染頁(yè)面抓取:Spla...
閱讀 3392·2021-09-22 15:17
閱讀 2740·2021-09-02 15:15
閱讀 1750·2019-08-30 15:54
閱讀 2001·2019-08-30 14:02
閱讀 2529·2019-08-29 16:58
閱讀 2988·2019-08-29 16:08
閱讀 1330·2019-08-26 12:24
閱讀 1653·2019-08-26 10:41