Python Selenium Data-style-name
So there's a bit of html that looks like this
Solution 1:
data-style-name
is called an attribute of your a
element and "Black" is its value.
Here is a way to access attribute's value with selenium & python:
elements = driver.find_elements_by_xpath("//a[@data-style-name]")
for element in elements:
print element.get_attribute("data-style-name")
If you want to select only elements with attribute data-style-name
with value "Black":
driver.find_elements_by_xpath("//a[@data-style-name=Black]")
More about xpath: https://www.w3.org/TR/xpath/#section-Introduction
Solution 2:
Have you try on find_element_by_xpath()
?
a_check = browser.find_element_by_xpath("/html/body/a[@data-style-name='Black']")
Which returns:
<selenium.webdriver.remote.webelement.WebElement (session="6c94ac24e0ec3a3320ec21b24055f4fa", element="0.1043557711542944-1")>
Post a Comment for "Python Selenium Data-style-name"