独自の待機条件を作成してWebDriverWait#untilに渡せばよいかと。
Python
1import random
2from selenium import webdriver
3from selenium.common.exceptions import TimeoutException
4from selenium.webdriver.support.ui import WebDriverWait
5
6
7def get_url() -> str:
8 URLS = ["https://www.google.co.jp/", "https://teratail.com/", "http://www.example.com/"]
9 return random.choice(URLS)
10
11
12def condition(driver) -> bool:
13 look_for = ['google', 'treratail', 'example']
14 url = driver.current_url
15 if any(url.find(s) != -1 for s in look_for):
16 print("match:{}".format(url))
17 return True
18
19 return False
20
21
22def main() -> None:
23 driver = webdriver.Chrome()
24 url = get_url()
25 print("req:{}".format(url))
26 try:
27 driver.get(url)
28 try:
29 WebDriverWait(driver, timeout=10).until(condition)
30 print("done:{}".format(driver.current_url))
31 except TimeoutException as ex:
32 print("#" * 80)
33 print(ex)
34 finally:
35 driver.quit()
36
37
38if __name__ == '__main__':
39 main()
40
■参考情報
5. Waits
expected-conditions-with-selenium-python
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/03/20 08:03 編集
2018/03/20 08:04