如何选择多个具有几乎相同xpath的元素?
我有一些具有以下 xpath 格式的元素:
//*[@id="dashboardRoot"]/span/div/div/div/div[1]/div/div/div[1]/main/div[2] /div[2]/div[1]/div/div/table/tbody/tr[i]
where i = 1,2,3,4,....etc
如何在循环中每次选择一个元素?
我尝试了这种方式:
for i in range(5):
try:
xpath = '//*[@id="dashboardRoot"]/span/div/div/div/div[1]/div/div/div[1]/main/div[2]/div[2]/div[1]/div/div/table/tbody/tr["i+1"]'
select_card = browser.find_element_by_xpath(xpath).click()
但它每次都适用于第一个元素,并且不会移动下一个元素。
提前致谢
i have some elements with the following xpath format:
//*[@id="dashboardRoot"]/span/div/div/div/div[1]/div/div/div[1]/main/div[2]/div[2]/div[1]/div/div/table/tbody/tr[i]
where i = 1,2,3,4,....etc
How to select an element every time in a loop?
i tried this way:
for i in range(5):
try:
xpath = '//*[@id="dashboardRoot"]/span/div/div/div/div[1]/div/div/div[1]/main/div[2]/div[2]/div[1]/div/div/table/tbody/tr["i+1"]'
select_card = browser.find_element_by_xpath(xpath).click()
but it works with the first element every time and don't move tho the next one.
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要将
i
值放入字符串中,您必须将其放入字符串格式,如下所示:或
to place the
i
value in the string, you must put it in the string format as below :or
使用 find elements 而不是 find element。您的代码应该是这样的:
Instead of find element,use find elements.your code should be this: