[英]Selenium/python - locating an element with the same ID
Ok, I have an iframe with 3 tabs. 好的,我有一个带3个标签的iframe。 On each of these tabs there is an element with the same ID, class but different value. 在每个选项卡上,都有一个具有相同ID,类但值不同的元素。 How am I supposed to locate each of them separately? 我应该如何分别定位它们?
First, make sure you know how to deal with iframes with Selenium and that it isn't a first blocker for you. 首先,请确保您知道如何使用Selenium处理iframe,并且它不是您的第一个阻止者。
Then to answer your question, you can either: 然后回答您的问题,您可以:
use an xpath selector: 使用xpath选择器:
*[@id="tabid"][1]
will select the first element with the id tabid
. *[@id="tabid"][1]
将选择ID为tabid
的第一个元素。 *[@id="tabid"][2]
will select the second element with the id tabid
. *[@id="tabid"][2]
将选择ID为tabid
的第二个元素。 use a CSS selector: 使用CSS选择器:
#tabid:nth-child(1)
#tabid:nth-child(2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.