Python Selenium Webdriver selectors

Posted on Updated on

from selenium import webdriver # import webdriver
browser = webdriver.Chrome() # initiate chrome browser for instance
browser.find_element_by_id('id of element to select') # return first element matched by the selector
browser.find_elements_by_id('id of element to select) # returns list of all elements matched by the selector
browser.find_element_by_xpath('selector expression')
browser.find_element_by_link_text('selector expression')
browser.find_element_by_partial_link_text('selector expression')
browser.find_element_by_name('selector expression')
browser.find_element_by_tag_name('selector expression')
browser.find_element_by_class_name('selector expression')
browser.find_element_by_css_selector('selector expression')

The function names are self explanatory. Every function has the element(s) version to return list of elements matched by the selector