I just want to access a xpath. But when I'm search this in inspect menu it finding 5 result. I want to access one of them not 5. How can I do it with index number? like...
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.
It's not working!
find_elements_by_xpathreturns a list, remove the index lookup in the xpath and index into the returned list?driver.find_elements_by_xpath(modified_xpath)[2]selenium.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.