selenium 定位元素方式大全

starts-with 顾名思义,匹配一个属性开始位置的关键字

contains 匹配一个属性值中包含的字符串

text() 匹配的是显示文本信息,此处也可以用来做定位用

eg

//input[starts-with(@name,'name1')]     查找name属性中开始位置包含'name1'关键字的页面元素

//input[contains(@name,'na')]         查找name属性中包含na关键字的页面元素

<a href="http://www.baidu.com">百度搜索</a>

xpath写法为 //a[text()='百度搜索'] 

或者 //a[contains(text(),"百度搜索")]

把看不到的元素拉到能看到的地方

driver.find_element_by_xpath("//div[contains(text(), "提交")]").location_once_scrolled_into_view

原文地址:https://www.cnblogs.com/xqnq2007/p/7921520.html