【发布时间】:2020-06-21 19:29:54
【问题描述】:
嗨,我想根据“ST”的following-sibling 输入值定位连接到名为“John Doe”的学生的 href 元素。这是我用来选择元素的代码:
driver.find_element_by_xpath('//a[following-sibling::input[@value="ST"]]/@href').click()
它正在定位正确的元素,但我得到了这个错误:
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.
我该如何解决这个问题?
【问题讨论】:
-
当您有文本输出时,don't take a picture but copy paste the output in your POST 也可以从浏览器控制台中复制 html:从检查器中,右键单击 -> 复制为 outerHTML。
-
您不能选择属性节点,它们不是作为单独的对象实现的。选择
<a>元素本身,然后使用 Python 代码获取属性值。 -
我不是在我的代码中选择了
<a>吗?
标签: python-3.x selenium selenium-webdriver xpath webdriver