Search code examples
pythonseleniumxpathsplinter

Selecting data-style-name in (Python/Splinter)


I'd like to select an item in a specific color from an unordered list. One poster in another thread suggested I try browser.find_by_xpath("/html/body/a[@data-style-name='COLOR HERE'", but that didn't work. The XPath (taken from the website) looks like this: /html/body/div[2]/div/div[2]/ul/li[2]/a[1]. How could click this option in Splinter?


Solution

  • You should try related XPath like

    //a[@data-style-name='COLOR HERE']
    

    because /html/body/a[@data-style-name='COLOR HERE'] means that target link is immediate child of body node which is obviously not true...