码迷,mamicode.com
首页 > 编程语言 > 详细

使用python处理selenium中的xpath定位元素的模糊匹配问题

时间:2017-12-14 03:43:31      阅读:450      评论:0      收藏:0      [点我收藏+]

标签:pytho   信息   star   问题   contains   image   images   定位   drive   

技术分享图片

# 用contains,寻找页面中style属性值包含有sp.gif这个关键字的所有div元素,其中@后面可以跟该元素任意的属性名。

self.driver.find_element_by_xpath(‘//div[contains(@style,"sp.gif")]‘).click()

# 用start-with,寻找style属性以position开头的div元素,其中@后面可以跟该元素任意的属性名。

self.driver.find_element_by_xpath(‘//div[start-with(@style,"position")]‘).click()

# 用Text,直接查找页面当中所有的退出二字,经常用于纯文字的查找。

self.driver.find_element_by_xpath(‘//*[text()="退出"]‘).click()

# 用于知道超链接上显示的部分或全部文本信息

self.driver.find_element_by_xpath(‘//a[contains(text(), "退出")]‘).click()

使用python处理selenium中的xpath定位元素的模糊匹配问题

标签:pytho   信息   star   问题   contains   image   images   定位   drive   

原文地址:http://www.cnblogs.com/sgwjj/p/8035613.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!