메소드 & 필드..
clear()
click()
find_element(by='id', value=None)
.
.
.
location
location_once_scrolled_into_view
parent
rect
screenshot
screenshot_as_base64
screenshot_as_png
send_keys
size
submit()
tag_name
text
value_of_css_property
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get(url)
id = 'id'
pw = '***'
id_text = browser.find_element_by_id("id")
pw_text = browser.find_element_by_id("password")
id_text.clear()
id_text.send_keys(id)
pw_text.clear()
pw_text.send_keys(pw)
# enter
pw_text.send_keys(Keys.RETURN)
find_element_by_id
find_element_by_name
find_element_by_xpath
find_element_by_link_text
find_element_by_partial_link_text
find_element_by_tag_name
find_element_by_class_name
find_element_by_css_selector
여러 요소 찾을때, list로 반환됨
find_elements_by_name
find_elements_by_xpath
find_elements_by_link_text
find_elements_by_partial_link_text
find_elements_by_tag_name
find_elements_by_class_name
find_elements_by_css_selector
Apart from the public methods given above, there are two private methods which might be useful for locating page elements:
find_element
find_elements
Example usage:
from selenium.webdriver.common.by import By
driver.find_element(By.XPATH, '//button[text()="Some text"]')
driver.find_elements(By.XPATH, '//button')
These are the attributes available for By class:
ID = "id"
XPATH = "xpath"
LINK_TEXT = "link text"
PARTIAL_LINK_TEXT = "partial link text"
NAME = "name"
TAG_NAME = "tag name"
CLASS_NAME = "class name"
CSS_SELECTOR = "css selector"
driver.find_elements_by_xpath(".//*")
driver.find_elements_by_id("id")
driver.find_element_by_id("id")
driver.execute_script('code')
# scrollTop += 50
driver.execute_script('return document.getElementsByClassName("y-scroll")[1].scrollTop += 50')
id = browser.execute_script('return info.id')
# click
driver..execute_script('return document.getElementsByClassName("sadfsdafsdaf")[0].click()')
div = driver.find_elements_by_id("div")
div[0].get_property("scrollTop")