xpath python selenium code example

Example 1: driver.find_element_by_xpath

driver.find_element_by_xpath('//*[@id="emailField"]')

Example 2: selenium select element by id

driver.findElement(By.id("ui-datepicker-div"));

Example 3: xpath parsing in python

try:
    # Python 2
    from urllib2 import urlopen
except ImportError:
    from urllib.request import urlopen
from lxml import etree

url =  "http://www.example.com/servlet/av/ResultTemplate=AVResult.html"
response = urlopen(url)
htmlparser = etree.HTMLParser()
tree = etree.parse(response, htmlparser)
tree.xpath(xpathselector)

Tags:

Misc Example