Java+Selenium3方法篇10-findElement之By PartialLinkText
来源:互联网 发布:单片机驱动无源蜂鸣器 编辑:程序博客网 时间:2024/05/16 03:31
这篇介绍findElement系列方法中的By PartialLinkText,看到这个是不是会想起By LinkText,没错。如果你看到一个有文字链接的元素,上面文字太多,你不想写这么多文字,那么你就可以用PartialLinkText,也就是用LinkText里面的一部分字符就可以定位该元素。这里建议,你选取的字符要有唯一性,也就是,根据你选取的字符,在当前页,只能找到你的目标元素。这里用百度首页的“把百度设为主页”这个元素来介绍PartialLinkText定位。
相关脚本代码如下:
package lessons;import java.util.concurrent.TimeUnit;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver; public class ByClassName { public static void main(String[] args) throws Exception { System.setProperty("webdriver.chrome.driver", ".\\Tools\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get("https://www.baidu.com"); driver.findElement(By.partialLinkText("设为主页")).click(); }}这里就需要用人工去判断,点击这个元素,打开的是不是百度设置主页的页面。目前,我们还没有介绍driver在多个浏览页面之间的跳转的方法,所以,这里就没有写自动化判断。
阅读全文
0 0
- Java+Selenium3方法篇10-findElement之By PartialLinkText
- Java+Selenium3方法篇5-findElement之By id
- Java+Selenium3方法篇6-findElement之By XPath
- Java+Selenium3方法篇7-findElement之By LinkText
- Java+Selenium3方法篇8-findElement之By ClassName
- Java+Selenium3方法篇9-findElement之By Name
- Java+Selenium3方法篇11-findElement之By CSS
- Java+Selenium3方法篇12-findElement之By TagName
- Java+Selenium3方法篇25-isDisplayed方法
- Java+Selenium3方法篇13-findElements举例
- Java+Selenium3方法篇39-Explicit wait
- Java+Selenium3方法篇41-FluentWait
- Java+Selenium3方法篇14-元素操作之输入和点击
- Java+Selenium3方法篇2-Timeout接口相关方法介绍
- Java+Selenium3方法篇3-window接口相关方法介绍
- Java+Selenium3方法篇30-Selenium中截图方法-TakeScreenshot
- Java+Selenium3方法篇4-Navigation接口介绍
- Java+Selenium3方法篇15-元素内清除文本操作
- 贪心算法实例(五):小船过河问题
- form中获取field+textfield赋值+combo的自动赋值+ 重置表单
- 网页服务器开发:CGI(2)
- Mybatis foreach 问题 Parameter 'item' not found
- HTTP协议详解
- Java+Selenium3方法篇10-findElement之By PartialLinkText
- Spring Security(19)——对Acl的支持
- 泛型与函数式比较
- WebRTC 初探
- 我的第一篇博客
- Android下面打印进程函数调用堆栈(dump backtrace)的方法
- C++类内存分布 通过Visual studio 2013查看
- 在NT中直接访问物理内存
- 找出奇数个数中唯一出现一次的数