0

Currently working on Web task automation.

When I go to the webpage I want, I have Selenium look for Elements using their Xpath

receivedTime = browser.find_elements_by_xpath('//*[starts-with(@id, "anchor") and contains(@id, "_0")]')
for time in receivedTime:

So it finds all those Elements. How would I go about retrieving which xpath is currently being used during the for Loop? So that I can use an If statement based on the current xpath.

For example, if the current xpath == "anchor0_0":

Thank you.

Crow
  • 15
  • 3
  • How those `anchors` looks like? Is it ordered sequence like `"anchor0_0", "anchor1_0", "anchor2_0"..."anchorN_0"`? – Andersson Nov 08 '18 at 16:10
  • Is your question duplicate to [this one](https://stackoverflow.com/questions/38127046/how-to-find-the-xpath-of-selenium-webdriver?rq=1) – stan Nov 08 '18 at 16:13

1 Answers1

0

You can check @id of each element as below:

receivedTime = browser.find_elements_by_xpath('//*[starts-with(@id, "anchor") and contains(@id, "_0")]')
for time in receivedTime:
    if time.get_attribute('id') == 'anchor0_0':
        # Do something
Andersson
  • 51,635
  • 17
  • 77
  • 129