python selenium使用xpath定位(python和java哪个更值得学)

网友投稿 465 2022-08-23


python selenium使用xpath定位(python和java哪个更值得学)

以上是普通的情况,存在可以定位的属性,当某个元素的各个属性及其组合都不足以定位时,我们可以利用其兄弟节点或者父节点等各种可以定位的元素进行定位,先看看xpath中支持的方法:

、child  选取当前节点的所有子元素

、parent  选取当前节点的父节点

、descendant选取当前节点的所有后代元素(子、孙等)

、ancestor  选取当前节点的所有先辈(父、祖父等)

、descendant-or-self选取当前节点的所有后代元素(子、孙等)以及当前节点本身

、ancestor-or-self  选取当前节点的所有先辈(父、祖父等)以及当前节点本身

、preceding-sibling选取当前节点之前的所有同级节点

、following-sibling选取当前节点之后的所有同级节点

、preceding   选取文档中当前节点的开始标签之前的所有节点

、following   选取文档中当前节点的结束标签之后的所有节点

、self  选取当前节点

、attribute  选取当前节点的所有属性

、namespace选取当前节点的所有命名空间节点

from selenium import webdriverdriver = webdriver.PhantomJS()driver.get("getPage_text = driver.find_element_by_class_name('lbf-pagination-item-list').find_element_by_xpath("li/a[@class='lbf-pagination-next ']").get_attribute("innerHTML")# 打印 ># getPage_text = driver.find_element_by_class_name('lbf-pagination-item-list').find_element_by_xpath("li/a[@class='lbf-pagination-next ']/parent::li[1]").get_attribute("innerHTML")# 打印 >getPage_text = driver.find_element_by_class_name('lbf-pagination-item-list').find_element_by_xpath("li/a[@class='lbf-pagination-next ']/parent::li[1]/preceding-sibling::li[1]").get_attribute("innerHTML")# 打印 108getPage_text = driver.find_element_by_class_name('lbf-pagination-item-list').find_element_by_xpath("li/a[@class='lbf-pagination-next ']/parent::li[1]/preceding-sibling::li[1]/descendant::a[1]").get_attribute("innerHTML")print(getPage_text) # 打印 108


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:在Python中寻找数据异常值的三种方法(python处理异常值的代码)
下一篇:Java设计模式之外观模式示例详解
相关文章

 发表评论

暂时没有评论,来抢沙发吧~