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...&nbsp;</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']")




转载于:https://www.cnblogs.com/ht22ht22/p/9672660.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值