无法在Selenium中通过css选择器获取元素

时间:2016-07-06 04:21:58

标签: selenium

我无法使用Python在Selenium中通过css选择器获取元素,因此我无法单击下载。这是我的代码是什么错误的?

link = u''

mydriver = webdriver.Firefox()

try:
    mydriver.get(link)
    btn = mydriver.find_element_by_css_selector("//a[class='button neutral']")
    print link

except Exception as e:
    print "link: {0}, exception: {1}".format(link, repr(e))

1 个答案:

答案 0 :(得分:3)

您使用XPath但不是css-selector。尝试

btn = mydriver.find_element_by_xpath("//a[@class='button neutral']")

如果您想使用css-selector尝试

mydriver.find_element_by_css_selector("a.button.neutral")
相关问题