xpath的定位方式
<div id="cnblogs_post_body" class="blogpost-body"><p>1.xpath较复杂的定位方法:</p>
a. 用contains关键字,定位代码如下:
driver.findElement(By.xpath(“//a[contains(@class, ‘blogpost’)]”));
<a target="_blank" href="https://www.baidu.com/link?url=imd349" class="c-showurl" style="text-decoration:none;">https://博客.csdn.net/duff2016... </a>、
b. 用start-with,定位代码如下:
driver.findElement(By.xpath(“//a[starts-with(@href, ‘https://www.ba’)]));
c. 用Text关键字,定位代码如下:
driver.findElement(By.xpath(“//a[contains(text(), ’博客’)]));
a.starts-with 例子: input[starts-with(@id,'ctrl')] 解析:匹配以 ctrl开始的属性值
b.ends-with 例子:input[ends-with(@id,'_userName')] 解析:匹配以 userName 结尾的属性值
c.contains() 例子:Input[contains(@id,'userName')] 解析:匹配含有 userName 属性值
By.xpath("//input[@type='name' and @name='kw1']")