Ok, I have an iframe with 3 tabs. On each of these tabs there is an element with the same ID, class but different value. How am I supposed to locate each of them separately?
Asked
Active
Viewed 2,335 times
0
-
Possibly with xpath or css. Provide the `html` of all three if possible – Saifur May 27 '15 at 15:02
-
1It is worth considering: same `id` on one page, is generally considered a bug. – SiKing May 27 '15 at 15:16
-
You should consider change the HTML to avoid duplication of ids according to the HTML specification. – segalaj May 27 '15 at 15:42
-
Perhaps this is not his own page. – Stéphane Bruckert May 27 '15 at 15:44
-
I know, I'll suggest this change to the our developer. – nvldk May 27 '15 at 20:51
1 Answers
0
First, make sure you know how to deal with iframes with Selenium and that it isn't a first blocker for you.
Then to answer your question, you can either:
use an xpath selector:
*[@id="tabid"][1]
will select the first element with the idtabid
.*[@id="tabid"][2]
will select the second element with the idtabid
.- etc.
use a CSS selector:
#tabid:nth-child(1)
#tabid:nth-child(2)
- etc.

Community
- 1
- 1

Stéphane Bruckert
- 21,706
- 14
- 92
- 130
-
To be more specific Tab1 has a button1 (id=submit, value=xx) Tab 2 has a button2 (id=submit, value=xy),..how do I locate for example: button 2? – nvldk May 27 '15 at 15:28
-
`//*[@id="tabid"][2]/button[@id='submit']` or directly `//*button[@id='submit'][2]`. – Stéphane Bruckert May 27 '15 at 15:47
-
I tried: driver.find_element_by_xpath("//*input[@id='submit'][2]").click() but I`m getting syntax error – nvldk May 27 '15 at 16:00
-
-
You have to [switch to the iframe](http://stackoverflow.com/questions/10879206/how-to-switch-between-frames-in-selenium-webdriver-using-java) first, did you do that? Can you access the iframe content? – Stéphane Bruckert May 28 '15 at 09:59