Summary for myself Updated from time to time ** I just need to know myself, so the terms may be wrong in some places **
!! View
#command
#Argument option description
#Webdriver
from selenium import webdriver
#webdriver wait module
from selenium.webdriver.support.ui import WebDriverWait
#Module to see how the elements are read
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By
#Webdriver option setting module(Chrome)
from selenium.webdriver.chrome.options import Options
#Used when sending values to elements
from selenium.webdriver.common.keys import Keys
#Start Webdriver
driver = webdriver.Chrome()
executable_path= #Webdriver storage path
chrome_options= #Boot options
#Wait until all elements are loaded
WebDriverWait(driver,15).until(ec.presence_of_all_elements_located)
#Wait until the element on the page with the specified ID is loaded (timeout judgment in 15 seconds)
WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.ID, 'ID name')))
#URL / HTML file connection
driver.get()
#URL or HTML path as an argument
#Get HTML
driver.get_source()
#Optional object creation
options = Options()
#Add options
options.add_argument()
'--headless' #Headless mode
#Get HTML
driver.get_source()
#Get window size
driver.get_window_size()
#Set window size
driver.set_window_size()
#The first argument is the width
#The second argument is the height
#Maximize the window
driver.maximize_window()
#Window positioning
driver.set_window_position(x,y)
#The first argument is the x coordinate
#The second argument is the y coordinate
#Get elements by ID, get multiple below
element = find_element_by_id()
elements = find_elements_by_id()
#Get elements by name, get multiple below
element = find_element_by_name()
elements = find_elements_by_name()
#Get elements with xpath, get multiple below
element = find_element_by_xpath()
elements = find_elements_by_xpath()
#Get elements with linktext, get multiple below
element = find_element_by_link_text()
elements = find_elements_by_link_text()
#Get elements by tag name, get multiple below
element = find_element_by_tag_name()
elements = find_elements_by_tag_name()
#Get elements by class name, get multiple below
element = find_element_by_class_name()
elements = find_elements_by_class_name()
#Get elements with css selector, get multiple below
element = find_element_by_css_selector()
elements = find_elements_by_css_selector()
#Click the retrieved element
element.click()
#Send value to the retrieved element
element.send_keys()
#Value to send to argument
#RETURN key on the retrieved element
element.send_keys(Keys.RETURN)
#Empty the input field
element.clear() #An error occurs when trying to erase even though there is no value
Recommended Posts