I am using Selenium
for Python 2.7.10
.
With XPath
, I would like to locate the link in a href
, following the sibling to minimal-list__title
(i.e. I'm looking for the child beneath minimal-list__value
). Which XPath should I use?
<span class="minimal-list__title">ETF Home Page:</span>
<span class="minimal-list__value">
<a href="http://www.robostoxetfs.com/">ROBO</a>
This is the current attempt:
from selenium import webdriver as driver
from selenium.common.exceptions import NoSuchElementException
def get_link(driver, key):
key = key + ":"
try:
find_value = driver.find_element_by_xpath("//span[@class='minimal-list__title' and . = '%s']/following-sibling::span/*[1]::a" % key).text
except NoSuchElementException:
return None
else:
value = re.search(r"(.+)", find_value).group().encode("utf-8")
return value
website = get_link(driver, "ETF Home Page")
print "Website: %s" % website
Note that I am specifically interested in a XPath that gets the link from the child of the following sibling. This is because the function above uses "ETF Home Page:"
in the web code as an identifier for what to search for.