반응형
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 |
Tags
- 날짜 정규식
- 네이버 로그인 캡챠해결
- 네이버 로그인 하기
- Element is not clickable at point
- 네이버커머스API
- 왕초보 파이썬 실행
- 파이썬 환경설정
- 네이버 로그인 영수증 해결
- UiPath
- selenium
- uipath 입문
- 가상환경설치
- Selenium 셀렉터잡기
- 커머스API
- pycdc.exe
- pywinauto 윈도우제어
- vscode venv 설치
- 파이썬 네이버 로그인
- 네이버부동산크롤링
- Uipath 설치방법
- venv 설치
- 파이썬 가상환경 설치
- pywinauto 윈도우
- Python
- Uipath 기초
- 네이버매물크롤링
- 파이썬네이버부동산
- 파이썬 가상환경 설치방법
- pycdas.exe
- pywinauto
Archives
- Today
- Total
콘솔워크
[selenium] EC(Expected Conditions)과 while문을 활용해 반복작업 하기 본문
반응형
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
def confirm_start(self):
driver = self.driver
have_list = True
while have_list:
try:
self.get_order_list()
except Exception as e:
print(f"주문 목록 로드 실패")
have_list = False
break
# 목록 로딩 대기
WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "#TBL_LIST tr"))
)
time.sleep(0.5)
try:
driver.implicitly_wait(5)
order_link = driver.find_element(By.CSS_SELECTOR, "#TBL_LIST tr a")
order_link.click()
# 작업영역 -> 구매확정
self.confirm_order()
time.sleep(1)
except Exception as e:
print(f"더 이상 물품이 없습니다.")
have_list = False
continue
finally:
driver.implicitly_wait(self.default_wait)
time.sleep(1)
위 코드는 테이블의 tr에 링크가 있는지 검색해보고 있는 경우에는 작업을, 없는 경우에는 except가 발생하여 반복문을 탈출하는 식으로 작업하였다.
만약 사이트 로딩상의 문제로
WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#TBL_LIST tr"))) 의 요소가 검색되었지만 클릭이 불가능한 경우에는
EC.element_to_be_clickable 을 사용해 해당 요소가 클릭이 가능한 상태인지로 바꿔주면 된다.
EC(Expected Conditions) 메소드 참고자료
7. WebDriver API — Selenium Python Bindings 2 documentation
A single IP address, as a string. If any IPv4 address is found, one is returned. Otherwise, if any IPv6 address is found, one is returned. If neither, then None is returned.
selenium-python.readthedocs.io
반응형
'프로그래밍 > python' 카테고리의 다른 글
[pyqt5] 아이콘 이미지 넣기 - jpg, png 활용 이미지 링크 가능 (0) | 2022.08.17 |
---|---|
[python] 암호화된 엑셀파일 읽기 함수 (dataframe으로 반환) (0) | 2022.08.12 |
[pywinauto] 윈도우창 현재 활성화 상태인지 확인 (0) | 2022.08.10 |
[python] dataframe 정리 (0) | 2022.08.10 |
[selenium] 새 탭에서 작업 후 원래 탭으로 돌아오기 (0) | 2022.08.09 |