以下是一组链接,<a elements. 只有其中一个链接有一个子字符串"long"作为属性href的值
<a class="c1" href= "very_lpng string" > name1 </a>
<a class="g2" href= "verylong string" > name2 </a> // The one that I need
<a class="g4" href= "very ling string" > name3 </a>
<a class="g5g" href= "very ng string" > name4 </a>
...................
Run Code Online (Sandbox Code Playgroud)
我需要单击其中href包含子字符串"long" 的链接.我怎样才能做到这一点?
PS:driver.findElement(By.partialLinkText("long")).click();// b/c它由名字选择
dda*_*son 97
I need to click the link who's href has substring "long" in it. How can I do this?
With the beauty of CSS selectors.
your statement would be...
driver.findElement(By.cssSelector("a[href*='long']")).click();
Run Code Online (Sandbox Code Playgroud)
This means, in english,
Find me any 'a' elements, that have the
hrefattribute, and that attributecontains'long'
You can find a useful article about formulating your own selectors for automation effectively, as well as a list of all the other equality operators. contains, starts with, etc... You can find that at: http://ddavison.io/css/2014/02/18/effective-css-selectors.html
使用 driver.findElement(By.partialLinkText("long")).click();
| 归档时间: |
|
| 查看次数: |
127267 次 |
| 最近记录: |