Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- sshpass
- port forwarding
- postgresql
- 실행권한
- PYTHON
- appium server
- nmap
- rethinkdb
- STF
- Jupyter Notebook
- STF_PortForwarding
- postgres
- appium
- GoCD
- ubuntu
- kitura
- nGrinder
- SWIFT
- openpyxl
- perfect
- mysql
- ftp
- centos
- ssh
- 28015
- nohup
- Jupyter
- insert
- create table
- Materials
Archives
- Today
- Total
don't stop believing
로딩이 끝날때까지 기다리자 (Waits) 본문
Selenium을 사용해 테스트를 할때 element를 찾을 수 있도록 Web Page가 로딩이 끝날때 까지 기다려야 합니다.
AJAX를 이용해 만든 Web의 경우 리소스가 로드하는데 부문별로 다를 수 있습니다.
Selenium에서는 두 가지 타입의 wait method를 제공합니다.
Explicit Waits
특정 상태가 될때까지 기다리고, 상태가 되면 바로 실행한다.
123456789101112131415from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECdriver = webdriver.Firefox()driver.get("http://somedomain/url_that_delays_loading")try:element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "myDynamicElement")))finally:driver.quit()
위 코드는 id 속성이 myDynamicElement인 element가 리턴될때까지 10초간 기다리는 것 입니다.
만약 10초 전에 page가 로딩되고 element가 실행된다면 EC는 true를 반환하게 됩니다.
Expected Conditins는 아래와 같은 method들을 제공합니다.
[http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.support.expected_conditions]
- title_is
- title_contains
- presence_of_element_located
- visibility_of_element_located
- visibility_of
- presence_of_all_elements_located
- text_to_be_present_in_element
- text_to_be_present_in_element_value
- frame_to_be_available_and_switch_to_it
- invisibility_of_element_located
- element_to_be_clickable
- staleness_of
- element_to_be_selected
- element_located_to_be_selected
- element_selection_state_to_be
- element_located_selection_state_to_be
- alert_is_present
아래 코드처럼 WebDriverWait의 시간을 미리 정의해 놓고 사용할 수도 있습니다.
1234from selenium.webdriver.support import expected_conditions as ECwait = WebDriverWait(driver, 10)element = wait.until(EC.element_to_be_clickable((By.ID, 'someid')))
Implicit Waits
지정한 시간(초)동안 기다린다.
123456from selenium import webdriverdriver = webdriver.Firefox()driver.implicitly_wait(10) # secondsdriver.get("http://somedomain/url_that_delays_loading")myDynamicElement = driver.find_element_by_id("myDynamicElement")
'Testing Automation > Selenium' 카테고리의 다른 글
Selenium (Python) 설치와 기본 사용해 보기 (Windows) (0) | 2018.01.30 |
---|---|
Selenium With Python Document (0) | 2017.11.07 |
find_element By로 정리하기 (2) | 2017.11.07 |
Selenium Locating Elements (python) (0) | 2017.11.07 |
Selenium IDG for Firefox Nightly (Windows) (0) | 2017.11.06 |