有谁知道你如何使用python webdriver绑定点击基于href的链接.在waitr-webdriver中,您可以执行以下操作:
browser.link(:href => "http://www.testsite.com/pageOne.html").click
但我无法在python webdriver中找到类似的功能.一切都有
find_element_by_class_name
find_element_by_css_selector
find_element_by_id
find_element_by_link_text
find_element_by_name
find_element_by_partial_link_text
find_element_by_tag_name
find_element_by_xpath
这些都是很好的方法,但我测试的网站在其链接中没有ID或类.因此,关于链接的唯一独特之处是href url.
任何帮助将不胜感激.
解决方法:
在封面下,watir-webdriver正在转换调用以找到href属性为给定值的链接到WebDriver find-by-XPath表达式中.在你自己的代码中模仿这个,在Python中处理它的适当方法是:
# assume driver is an instance of WebDriver
# NOTE: this code is untested
driver.find_element_by_xpath(".//a[@href='http://www.testsite.com/pageOne.html']")
或者,您可以使用CSS选择器(在IE上会更快),如下所示:
# again, assume driver is an instance of WebDriver
# NOTE: this code is untested
driver.find_element_by_css_selector("a[href='http://www.testsite.com/pageOne.html']")
标签:python,click,selenium,webdriver