0

Once I obtain an href through the use of Selenium in Python.

Is there a way to find the XPath based on that href and click on that XPath?

For Example:

href = '/sweatshirts/vct65b9ze/yn2gxohw4' 

How would I find the XPath on that page?

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
Teddy
  • 55
  • 1
  • 2
  • 4
  • 1
    Possible duplicate of [Is there a way to find an element by attributes in Python Selenium?](https://stackoverflow.com/questions/28426645/is-there-a-way-to-find-an-element-by-attributes-in-python-selenium) – JeffC Nov 12 '17 at 00:17

1 Answers1

2

When the element is for instance a link, you can use the following code:

     driver.find_element_by_xpath('//a[@href="/sweatshirts/vct65b9ze/yn2gxohw4"]');
Koen Meijer
  • 811
  • 11
  • 19