This error message...
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: The result of the xpath expression "//a[following-sibling::input[@value="ST"]]/@href" is: [object Attr]. It should be an element.
......implies that your XPath expression was not a valid xpath expression.
For the record
Selenium WebDriver supports xpath-1.0 only which returns the set of node(s) selected by the xpath.
You can find the xpath-1.0 specifications in XML Path Language (XPath) Version 1.0
Where as the xpath expression you have used:
driver.find_element_by_xpath('//a[following-sibling::input[@value="ST"]]/@href')
Is a xpath-2.0 based expression and would typically return an object Attr
. A couple of examples:
//@version
: selects all the version attribute nodes that are in the same document as the context node
../@lang
: selects the lang attribute of the parent of the context node
You can find the xpath-2.0 specifications in XML Path Language (XPath) 2.0 (Second Edition)
Solution
To locate the desired element with a href attribute connected to a student named "John Doe" based on the following-sibling input value of ST you can use either of the following xpath based Locator Strategies: