1
 self.driver.find_element_by_xpath("//span[@class='bog']").click()

This is my current code. Using this method. I can click on the first email of my gmail inbox. I want to then click on the second email or the third. But I'm unsure how to do it

self.driver.find_element_by_xpath("//span[@class='bog' and @xpath='2']").click()

I tried this method but it didn't work. Using chropath. I was able to search for "bog" and then find out a list of all the emails and each one showed an:

"<span id=":2y" class="bog" xpath="1"></span>"
"<span id=":2y" class="bog" xpath="2"></span>"

Any help regarding this issue? I would like to able to click on the second email of my inbox every time.

2 Answers 2

1

You can use xpath indexing :

for this xpath :

//span[@class='bog']

you can have index like below :

(//span[@class='bog'])[1]

will represent 1st element. [2] will represent 2nd element and [3] will represent 3rd element and so on..

in code :

self.driver.find_element_by_xpath("(//span[@class='bog'])[1]").click()

or

self.driver.find_element_by_xpath("(//span[@class='bog'])[2]").click()
Sign up to request clarification or add additional context in comments.

Comments

1

Check this you change the index from [2],[3],[4] it will access the particular element on that particular index

self.driver.find_element_by_xpath("((//span[@class='bog'])[2])").click()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.