[JAVA #9] [Web Automation #9] Controlling STEEMIT web pages with Selenium #7 Timeouts [CN] by june0620

View this thread on steempeak.com
· @june0620 ·
$10.18
[JAVA #9] [Web Automation #9] Controlling STEEMIT web pages with Selenium #7 Timeouts [CN]
![redsjavahouse1591357_1280.jpg](https://steemitimages.com/0x0/https://files.steempeak.com/file/steempeak/june0620/DKldjbG3-reds-java-house-1591357_1280.jpg)
image source: [pixabay](https://pixabay.com/photos/red-s-java-house-eatery-cafe-1591357/0)

---

今天让我们学习selenium 的Timeouts。 它属于manage()函数内并提供如下三个函数。
![image.png](https://steemitimages.com/0x0/https://files.steempeak.com/file/steempeak/june0620/LA2B3HgX-image.png)

##### 1. implicitlyWait

这孩纸在 Webdriver 期已经解释过。
[[JAVA 6#] [Web Automation 6#] Controlling STEEMIT web pages with Selenium #4 WebDriverWait [KR]](https://steemit.com/kr/@june0620/java-6-web-automation-6-controlling-steemit-web-pages-with-selenium-4-webdriverwait-kr)

##### 2. pageLoadTimeouts
如其名就是等到页面全部加载, 如超过设定的时间就抛出 TimeOutException。
参数由 time和时间单位组成, 设置 time为负数就一直等待。 👇

```
driver.manage().timeouts().pageLoadTimeout(-1, TimeUnit.SECONDS);
```

**次函数值适用与 Selenium的 `driver.get()`及 `driver.navigate().to()`。即对点击页面元素无效果。**
用于性能测试或者IE浏览器测试时有效果。

##### 3. setScriptTimeout

可以设置非同步超时时间,超时则抛出 TimeOutException。
次函数值影响到 executeAsyncScript函数,不影响 executeScript 函数。

再一个,用 executeAsyncScript时必须设置 setScriptTimeout。因为 setScriptTimeout 默认值是0,但是javascript执行时间一般超过零。

---

```
package com.steem.webatuo;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;

import io.github.bonigarcia.wdm.WebDriverManager;

public class Steemit {

 public static void main(String[] args) throws InterruptedException {
 WebDriverManager.chromedriver().setup();
 WebDriver driver = new ChromeDriver();
 
 driver.get("https://steemit.com");
 driver.manage().timeouts().setScriptTimeout(20, TimeUnit.SECONDS);
 driver.manage().timeouts().pageLoadTimeout(4, TimeUnit.SECONDS);
 driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
 
 Wait<WebDriver> wait = new WebDriverWait(driver, 10);
 
 /**
  * Some actions
  */
 
 Thread.sleep(5000);
 driver.quit();
 }

}

```

.
.
.
.
[Cookie 😅]
Seleniun java lib version: 3.141.59
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 72 others
👎  
properties (23)
post_id84,247,038
authorjune0620
permlinkjava-9-web-automation-9-controlling-steemit-web-pages-with-selenium-7-timeouts-cn
categorysct
json_metadata{"tags":["sct","sct-cn","sct-freeboard","cn","cn-stem","mini","steemstem","zzan","palnet","java"],"image":["https:\/\/steemitimages.com\/0x0\/https:\/\/files.steempeak.com\/file\/steempeak\/june0620\/DKldjbG3-reds-java-house-1591357_1280.jpg","https:\/\/steemitimages.com\/0x0\/https:\/\/files.steempeak.com\/file\/steempeak\/june0620\/LA2B3HgX-image.png"],"links":["https:\/\/pixabay.com\/photos\/red-s-java-house-eatery-cafe-1591357\/0","https:\/\/steemit.com\/kr\/@june0620\/java-6-web-automation-6-controlling-steemit-web-pages-with-selenium-4-webdriverwait-kr"],"app":"steemcoinpan\/0.1","format":"markdown","canonical_url":"https:\/\/www.steemcoinpan.com\/@june0620\/java-9-web-automation-9-controlling-steemit-web-pages-with-selenium-7-timeouts-cn"}
created2020-02-10 13:42:48
last_update2020-02-10 13:42:48
depth0
children7
net_rshares30,382,276,472,899
last_payout2020-02-17 13:42:48
cashout_time1969-12-31 23:59:59
total_payout_value5.606 SBD
curator_payout_value4.572 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length2,099
author_reputation219,336,602,045,061
root_title"[JAVA #9] [Web Automation #9] Controlling STEEMIT web pages with Selenium #7 Timeouts [CN]"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (137)
@annepink ·
@tipu curate 
这下巧了😅
!shop

Posted using [Partiko Android](https://partiko.app/referral/annepink)
properties (22)
post_id84,247,128
authorannepink
permlinkannepink-re-june0620-java-9-web-automation-9-controlling-steemit-web-pages-with-selenium-7-timeouts-cn-20200210t134653877z
categorysct
json_metadata{"app":"partiko","client":"android"}
created2020-02-10 13:46:54
last_update2020-02-10 13:46:54
depth1
children2
net_rshares0
last_payout2020-02-17 13:46:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length96
author_reputation160,119,580,804,298
root_title"[JAVA #9] [Web Automation #9] Controlling STEEMIT web pages with Selenium #7 Timeouts [CN]"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@tipu ·
<a href="https://tipu.online/curator?annepink" target="_blank">Upvoted &#128076;</a> (Mana: 5/15 - <a href="https://steempeak.com/steem/@tipu/tipu-curate-project-update-recharging-curation-mana" target="_blank">need recharge</a>?)
properties (22)
post_id84,247,133
authortipu
permlinkre-annepink-re-june0620-java-9-web-automation-9-controlling-steemit-web-pages-with-selenium-7-timeouts-cn-20200210t134653877z-20200210t134712
categorysct
json_metadata{}
created2020-02-10 13:47:09
last_update2020-02-10 13:47:09
depth2
children0
net_rshares0
last_payout2020-02-17 13:47:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length230
author_reputation55,804,171,747,699
root_title"[JAVA #9] [Web Automation #9] Controlling STEEMIT web pages with Selenium #7 Timeouts [CN]"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@june0620 ·
哈哈😄 谢谢~ 🤩
properties (22)
post_id84,247,613
authorjune0620
permlinkre-annepink-2020210t2362516z
categorysct
json_metadata{"tags":["esteem"],"app":"esteem\/2.2.4-mobile","format":"markdown+html","community":"hive-125125"}
created2020-02-10 14:06:24
last_update2020-02-10 14:06:24
depth2
children0
net_rshares0
last_payout2020-02-17 14:06:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length9
author_reputation219,336,602,045,061
root_title"[JAVA #9] [Web Automation #9] Controlling STEEMIT web pages with Selenium #7 Timeouts [CN]"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@teamcn-shop ·
你好鸭,june0620!

@annepink给您叫了一份外卖!

由 @xiaoyuanwmm 村凤 迎着海啸 undefined 给您送来
**巧克力蛋糕** <br> ![](https://steemitimages.com/0x0/https://cdn.steemitimages.com/DQma1eqtjk48SZHV2gjMPrJKVEDrXgYMD9MkyY58YSwP6LT/JPEG_20180525_134924_5872129153971841949.jpg)
吃饱了吗?跟我猜拳吧! **石头,剪刀,布~**

如果您对我的服务满意,请不要吝啬您的点赞~
@onepagex
properties (22)
post_id84,247,132
authorteamcn-shop
permlinkannepink-re-june0620-java-9-web-automation-9-controlling-steemit-web-pages-with-selenium-7-timeouts-cn-20200210t134653877z
categorysct
json_metadata"{"app":"teamcn-shop bot\/1.0"}"
created2020-02-10 13:47:06
last_update2020-02-10 13:47:06
depth1
children0
net_rshares0
last_payout2020-02-17 13:47:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length304
author_reputation66,408,278,506,348
root_title"[JAVA #9] [Web Automation #9] Controlling STEEMIT web pages with Selenium #7 Timeouts [CN]"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@sunai ·
来啪了
properties (22)
post_id84,247,546
authorsunai
permlinkq5hoeg
categorysct
json_metadata{"app":"busy\/2.5.4"}
created2020-02-10 14:03:54
last_update2020-02-10 14:03:54
depth1
children1
net_rshares0
last_payout2020-02-17 14:03:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length3
author_reputation82,963,848,333,719
root_title"[JAVA #9] [Web Automation #9] Controlling STEEMIT web pages with Selenium #7 Timeouts [CN]"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@june0620 ·
多谢🤩😀
properties (22)
post_id84,247,833
authorjune0620
permlinkre-sunai-2020210t23160377z
categorysct
json_metadata{"tags":["esteem"],"app":"esteem\/2.2.4-mobile","format":"markdown+html","community":"hive-125125"}
created2020-02-10 14:16:00
last_update2020-02-10 14:16:00
depth2
children0
net_rshares0
last_payout2020-02-17 14:16:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length4
author_reputation219,336,602,045,061
root_title"[JAVA #9] [Web Automation #9] Controlling STEEMIT web pages with Selenium #7 Timeouts [CN]"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000