我有这样的代码:

我有个问题,clicking a button。
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Editează'])[20]/following::a[1]").click()我收到这个错误:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"(.//*[normalize-space(text()) and normalize-space(.)='Editează'])[20]/following::a[1]"}
(Session info: chrome=73.0.3683.86)有什么想法吗?
发布于 2019-03-23 16:52:28
我不是xPath的专家,但我的理解是
.//*[normalize-space(text()) and normalize-space(.)='Editează'])[20]会带你找到Editează的第20个元素。在这种情况下,它已经是一个链接(一个标签)。
因此,/following::a[1]将尝试在链接中找到链接--这将导致失败。
也许只有
//a[text()='Editează'][20]就够了。
发布于 2019-03-23 21:00:10
如果这是表最后一个tr的最后一个td,我建议使用
//table/tr[last()]/td[last()]/a[contains(@href,'edit')]特别是如果网站是多语言的,而且您不是要检查按钮的文本,而是试图实现编辑操作。
https://sqa.stackexchange.com/questions/38393
复制相似问题