我只想访问一个XPath。但是在检查菜单中搜索时,它找到了5个结果。我想访问其中的一个而不是5个。如何使用索引编号实现?就像...
xpath = "//a[@role='button']" # 5 elements available with this xpath
modified_xpath = "//a[@role='button'][2]" # I'm trying with the index number.
driver.find_element_by_xpath(modified_xpath).click() # But It's not working.
“它不起作用了!”
find_elements_by_xpath
returns a list, remove the index lookup in the xpath and index into the returned list?driver.find_elements_by_xpath(modified_xpath)[2]
- Iain Shelvingtonselenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //a[@role='button'] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//a[@role='button']' is not a valid XPath expression.
- Priya