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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s