我有一个xpath,它可以在python-scrapy中运行,也可以在firefox的firebug扩展中运行。但是,它不适用于python-selenium。我在selenium中使用的代码就是这个
xpath = ".//div[@id='containeriso3']/div/a[1]/@href"
browser.find_element_by_xpath(xpath)
这会产生InvalidSelectorException错误。 selenium是否使用其他一些xpath版本?
答案 0 :(得分:3)
这不会让你成为一个元素。您需要关闭@href
属性。
使用.//div[@id='containeriso3']/div/a[1]
然后使用get_attribute
从中获取href
。