My Webdriver (Python)

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

Module loading

#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

WebDriver Frequent operation

Start-connect
#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()

Option setting
#Optional object creation
options = Options()

#Add options
options.add_argument()
    '--headless' #Headless mode
Window operation
#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 and manipulate elements
#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

My Webdriver (Python)
My Numpy (Python)
My sys (python)
My pyproj (python)
My str (python)
My PySide (Python)
My shutil (python)
My matplotlib (python)
My urllib (python)
My sklearn (python)
[My memo] python
My ConfigParser (Python)
My arcpy (python)
My win32gui (Python)
My os (python)
My python environment memo
My Beautiful Soup (Python)
Drive WebDriver with python
Python Tips (my memo)
My python data analysis container
Python
[Python] Eliminate Chrome Webdriver errors
Selenium WebDriver + Firefox49 (provisional) (Python)
My python data analytics environment
Challenge Python3 and Selenium Webdriver
[Python] My stock price forecast [HFT]
My favorite boto3 (Python) API sample
Python My Number verification module released
kafka python
Python basics ⑤
python + lottery 6
Built-in python
Python comprehension
Python technique
Studying python
Python 2.7 Countdown
Python memorandum
Python FlowFishMaster
Python service
python function ①
Python basics
Python memo
ufo-> python (3)
Python comprehension
install python
Python Singleton
Python basics ④
Python Memorandum 2
python memo
Python Jinja2
Python increment
python tips
Installing Python 3.4.3.
Try python
Python memo
Python iterative
Python algorithm
[Python] Variables
Python functions
Python sys.intern ()
Python decimals