기계는 거짓말하지 않는다

Python Selenium WebDriver 사용법, 메서드 본문

Python

Python Selenium WebDriver 사용법, 메서드

KillinTime 2021. 7. 24. 01:22

설치

pip install selenium

WebDriver Access 방법

from selenium import webdriver

driver_path = "./driverDirectory"

driver = webdriver.Firefox(driver_path)
# 위와 동일
'''
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote(driver_path)
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
'''

# key와 관련된 import
from selenium.webdriver.common.keys import Keys

Remote WebDriver WebElement

자주 사용되는 메서드

Link: CSS Selector 연습

메서드 설명
clear() text element인 경우 text를 지움
click() element 클릭
ㅡㅡㅡㅡ element 찾기 ㅡㅡㅡㅡ
find_element_by_class_name(name) 현재 element 내의 class이름으로 element를 찾음
find_element_by_css_selector(css_selector) 현재 element 내의 css선택자로 element를 찾음
find_element_by_id(id) 현재 element 내의 id로 element를 찾음
find_element_by_name(name) 현재 element 내의 name으로 element를 찾음
find_element_by_tag_name(name) 현재 element 내의 tag로 element를 찾음
find_element_by_xpath(xpath) xpath로 element를 찾음
ㅡㅡㅡㅡ 복수의 element 찾기 (elements) ㅡㅡㅡㅡ
find_elements_by_class_name(name) 현재 element 내의 class이름으로 element list를 찾음
find_elements_by_css_selector(css_selector) 현재 element 내의 css선택자로 element list를 찾음
find_elements_by_id(id) 현재 element 내의 id로 element list를 찾음
find_elements_by_name(name) 현재 element 내의 name으로 element list를 찾음
find_elements_by_tag_name(name) 현재 element 내의 tag로 element list를 찾음
find_elements_by_xpath(xpath) xpath element 내의 element를 찾음
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
get_attribute(name) element의 지정된 속성을 가져옴
get_property(name) element의 property(html DOM attribute)를 가져옴
is_displayed() element가 사용자에게 표시되는지 여부
is_enabled() element가 활성화되었는지 여부
is_selected() element가 선택되었는지 여부
screenshot(filename) 현재 element의 스크린샷을 PNG 이미지 파일에 저장
send_keys(*value) element에 대한 key 입력
submit() form submit

 

'Python' 카테고리의 다른 글

Python zip 함수  (0) 2021.07.25
Python Selenium 크롤링 창 숨기기  (0) 2021.07.25
Python Matplotlib 폰트 확인, 적용  (0) 2021.07.23
Python BeautifulSoup 사용법, 속성  (0) 2021.07.20
Python Selenium, BeautifulSoup  (0) 2021.07.19
Comments