美文网首页
WebDriver API---八大定位

WebDriver API---八大定位

作者: 小胖5920 | 来源:发表于2019-06-12 16:36 被阅读0次

1.id定位
webDriver.findElement(By.id("id"))
2.name定位
webDriver.findElement(By.name("name"))
3.class定位
webDriver.findElement(By.className("classname"))
4.tag定位(标签名称定位)
webDriver.findElement(By.tagName("tagname"))
5.link定位(专门用来定位链接)
<a>新闻</a>
webDriver.findElement(By.linkText("新闻"))
方法通过元素标签之间的文本信息来定位元素
6.partial link定位
partial link定位是对link定位的一种补充,有些文本链接会比较长,这时候我们可以用文本链接来定位,但是这个部分拦击可以唯一的认识这个链接
<a>我是一个很长的链接</a>
webDriver.findElement(By.partialLinkText("我是一个很"))
7.xpath定位
webDriver.findElement(By.xpath("/html/body/div[5]/div[1]/button[2]"))
webDriver.findElement(By.xpath("//*[@id="username"]"))
8.CSS定位
webDriver.findElement(By.cssSelector(".class"))

在不同的场景会使用不同的定位,建议只用id、name、class、xpath

相关文章

网友评论

      本文标题:WebDriver API---八大定位

      本文链接:https://www.haomeiwen.com/subject/mcvlfctx.html