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