Java+Selenium3方法篇15-元素内清除文本操作
来源:互联网 发布:深圳策略一二三网络 编辑:程序博客网 时间:2024/06/05 07:15
本篇介绍元素操作之清除文本,这个清除动作,我们经常用,例如在某一个网站登录界面,有时候有些设计会自动记录用户名,但是我们自动化测试,需要换一个用户名登录,这个时候,最好就先清除用户名输入框文字,然后重新输入。这个方法,很简单,我们直接用一个示例就可以掌握。
package lessons;import java.util.concurrent.TimeUnit;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;public class ElementOpration {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"); WebElement ele = driver.findElement(By.id("kw")); ele.sendKeys("Java Selenium 教程"); Thread.sleep(200); ele.clear(); } }除了clear()方法,其实我们还有一种删除文字方式,全选输入框内部文字,然后按下backspace键。由于Selenium for java不像Python那么直接调用sendKeys(keys.CTRL+ 'a')能够处理,所以这里就先不介绍,等在介绍不同键盘事件再次介绍。
阅读全文
1 0
- Java+Selenium3方法篇15-元素内清除文本操作
- Java+Selenium3方法篇14-元素操作之输入和点击
- Java+Selenium3方法篇33-Actions-拖拽操作
- Java+Selenium3方法篇47-字符串切片操作
- Java+Selenium3方法篇25-isDisplayed方法
- Java+Selenium3方法篇27-利用JS处理元素高亮显示
- Java+Selenium3方法篇46-自定义类库解决元素同步问题
- Java+Selenium3方法篇13-findElements举例
- Java+Selenium3方法篇39-Explicit wait
- Java+Selenium3方法篇41-FluentWait
- Java+Selenium3方法篇24-单选和多选按钮操作
- Java+Selenium3方法篇43-利用Jexcel操作2003版本excel
- Java+Selenium3方法篇24-单选和多选按钮操作
- Java+Selenium3方法篇2-Timeout接口相关方法介绍
- Java+Selenium3方法篇3-window接口相关方法介绍
- Java+Selenium3方法篇30-Selenium中截图方法-TakeScreenshot
- Java+Selenium3方法篇4-Navigation接口介绍
- Java+Selenium3方法篇5-findElement之By id
- 删除Eclipse导入的epf主题的正确方式
- STM32--时钟树
- 【面试题】字符串旋转
- ubuntu16.04安装nginx教程
- Android的Message机制
- Java+Selenium3方法篇15-元素内清除文本操作
- 最简化安装centos6.5
- 登录mysql的没密码忘记了怎么办
- less-mixin(混合)
- 【快捷键】IntelliJ新建一个类 和 生成getter/setter方法的快捷键
- HashMap扩容机制
- Linux学习基础篇(七)
- 第三方支付架构设计之:商户回调通知系统的悲观和乐观策略
- 2017-6-10-1 ······开机自动检测并发送IP地址到指定邮箱