• 웹 앱을 테스트하는데 이용하는 프레임워크
• webdriver라는 API를 통해 운영체제에 설치된 Chrome등의 브라우저를 제어
• 참고 : https://sites.google.com/a/chromium.org/chromedriver/downloads
Downloads - ChromeDriver - WebDriver for Chrome
WebDriver for Chrome
sites.google.com
• 참고 : https://www.seleniumhq.org
SeleniumHQ Browser Automation
If you want to create robust, browser-based regression automation suites and tests, scale and distribute scripts across many environments, then you want to use Selenium WebDriver, a collection of language specific bindings to drive a browser - the way it i
selenium.dev
• 참고 : https://selenium-python.readthedocs.io/index.html
Selenium with Python — Selenium Python Bindings 2 documentation
Note This is not an official documentation. If you would like to contribute to this documentation, you can fork this project in Github and send pull requests. You can also send your feedback to my email: baiju.m.mail AT gmail DOT com. So far 40+ community
selenium-python.readthedocs.io
• selenium 설치 방법
pip install selenium
• 사용 법
from selenium import webdriver
driver=webdriver.Chrome('C:\\chromedriver\\chromedriver')
• 실행 시 새 창으로 빈 화면 뜨면 정상 실행
• 종료 방법
driver.quit()
• Quit를 안하면 프로세스에 남아서 PC가 무거워진다.
• 여러 개의 요소 중 처음 찾아지는 요소를 추출
메서드명 |
설명 |
find_element_by_id(id) |
id 속성으로 요소를 하나 추출 |
find_element_by_name(name) |
name 속성으로 요소를 하나 추출 |
find_element_by_css_selector(query) |
CSS 선택자로 요소를 하나 추출 |
find_element_by_xpath(query) |
XPath를 지정해 요소를 하나 추출 |
find_element_by_tag_name(name) |
태그 이름이 name에 해당하는 요소를 하나 추출 |
find_element_by_link_text(text) |
링크 텍스트로 요소를 추출 |
find_element_by_partial_link_text(text) |
링크의 자식 요소에 포함돼 있는 텍스트로 요소를 하나 추출 |
find_element_by_class_name(name) |
클래스 이름이 name에 해당하는 요소를 하나 추출 |
• 모든 요소 추출
메서드명 |
설명 |
find_elements_by_css_selector(query) |
CSS 선택자로 요소를 여러개 추출 |
find_elements_by_xpath(query) |
XPath를 지정해 요소를 여러개 추출 |
find_elements_by_tag_name(name) |
태그 이름이 name에 해당하는 요소를 여러개 추출 |
find_elements_by_class_name |
클래스 이름이 name에 해당하는 요소를 여러 개 추출 |
find_elements_by_partial_link_text(text) |
링크의 자식 요소에 포함돼 있는 텍스트로 요소를 여러 개 추출 |
• 적용할 수 있는 메서드와 속성
메서드명 |
설명 |
clear() |
글자를 입력할 수 있는 요소의 글자를 지움 |
click() |
요소를 클릭 |
get_attribute(name) |
요소의 속성 중 name에 해당하는 속성의 값을 추출 |
is_displayed() |
요소가 화면에 출력되는지 확인 |
is_enabled() |
요소가 활성화돼 있는지 확인 |
is_selected() |
체크박스 등의 요소가 선택된 상태인지 확인 |
screenshot(filename) |
스크린샷을 찍음 |
send_keys(value) |
키를 입력 |
submit() |
입력 양식을 전송 |
• 적용할 수 있는 메서드와 속성
메서드명 |
설명 |
value_of_css_property(name) |
name에 해당하는 CSS 속성의 값을 추출 |
id |
요소의 id 속성 |
location |
요소의 위치 |
parent |
부모 요소 |
rect |
크기와 위치 정보를 가진 딕셔너리 자료형을 반환 |
screenshot_as_base64 |
스크린샷을 Base64로 추출 |
size |
요소의 크기 |
tag_name |
태그 이름 |
text |
요소 내부의 글자 |
from selenium.Webdriver.common.keys import keys
• 드라이버 조작
메서드명 |
설명 |
add_cookie(cookie_dict) |
쿠키 값을 딕셔너리 형식으로 지정 |
back()/forward() |
이전 페이지 또는 다음 페이지로 이동 |
close() |
브라우저를 닫음 |
current_url |
현재 URL을 추출 |
delete_all_cookies() |
모든 쿠키를 제거 |
delete_cookie(name) |
특정 쿠키를 제거 |
execute(command, params) |
브라우저 고유의 명령어를 실행 |
execute_async_script(script, *args) |
비동기 처리하는 자바스크립트를 실행 |
execute_script(script, *args) |
동기 처리하는 자바스크립트를 실행 |
'Python_Crawling > Crawling' 카테고리의 다른 글
[Selenium]Python Study - PPT Presentation Material - 3 (0) | 2019.12.18 |
---|---|
[Selenium]Python Study - PPT Presentation Material - 2 (0) | 2019.12.18 |
[Crawling]Python Study - PPT Presentation Material - 4 (0) | 2019.12.16 |
[Crawling]Python Study - PPT Presentation Material - 3 (0) | 2019.12.16 |
[Crawling]Python Study - PPT Presentation Material - 2 (0) | 2019.12.16 |