selenium常用命令之操作页面元素及获取元素内容的事件整理
2016-06-17 22:00
531 查看
/**id <input type="text" id="phone" name="phone" class="LoginText" placeholder="手机号" >
* <button class="LoginBtn" id="btnLogin" value="baidu"> 登录</button>*/
WebElement byName=driver.findElement(By.name("phone"));
WebElement byLoginButton=driver.findElement(By.id("btnLogin"));
System.out.println(byName.getText());
1、click()事件源于单击元素操作
byLoginButton.click();
2、sendKeys()方法用于给input元素赋值
byName.sendKeys("13600000000");
3、clear()用于清空input元素的值
byName.clear();
4、Submit()用于提交表单
byLoginButton.submit();
5、getTitle()获取当前网页的标题
String title=driver.getTitle();
6、getCurrentUrl()获取当前网页的URL
String url=driver.getCurrentUrl();
7、getText()用于存储元素的文本值,例如纯文本、超链接等;
String text=byName.getText();
8、isSelected()用于存储复选框或单选框的勾选情况,返回true(勾选)或false(未勾选)
/**<input id="TANGRAM__PSP_8__memberPass" type="checkbox" name="memberPass" class="pass-checkbox-input pass-checkbox-memberPass" checked="checked">*/
WebElement checkBox=driver.findElement(By.id("TANGRAM__PSP_8__memberPass"));
boolean isSelected=checkBox.isSelected();
9、getTagName()获取元素的标记名称
String tagName=byName.getTagName();
10、isEnabled()用于存储input等元素的可编辑状态,例如:文本框、复选框、单选框;返回true(可编辑)或false(不可编辑)
boolean enabled=checkBox.isEnabled();
11、getAttribute()用于获取指定属性的值
String btnValue=byLoginButton.getAttribute("value");
12、窗口最大化
driver.manage().window().maximize();
13、accept()方法是单击弹出的对话框的确认按钮,例如:Alert,Confirmation,Prompt
driver.switchTo().alert().accept();
14、dismiss()方法实现单击弹出对话框的取消按钮;
driver.switchTo().alert().dismiss();
15、getText()获取弹出对话框的文本内容
driver.switchTo().alert().getText();
16、获取当前cookie的集合
Set<Cookie> cookie=driver.manage().getCookies();
17、refresh()页面刷新
driver.navigate().refresh();
/**id <input type="text" id="phone" name="phone" class="LoginText" placeholder="手机号" >
* <button class="LoginBtn" id="btnLogin" value="baidu"> 登录</button>*/
WebElement byName=driver.findElement(By.name("phone"));
WebElement byLoginButton=driver.findElement(By.id("btnLogin"));
System.out.println(byName.getText());
1、click()事件源于单击元素操作
byLoginButton.click();
2、sendKeys()方法用于给input元素赋值
byName.sendKeys("13600000000");
3、clear()用于清空input元素的值
byName.clear();
4、Submit()用于提交表单
byLoginButton.submit();
5、getTitle()获取当前网页的标题
String title=driver.getTitle();
6、getCurrentUrl()获取当前网页的URL
String url=driver.getCurrentUrl();
7、getText()用于存储元素的文本值,例如纯文本、超链接等;
String text=byName.getText();
8、isSelected()用于存储复选框或单选框的勾选情况,返回true(勾选)或false(未勾选)
/**<input id="TANGRAM__PSP_8__memberPass" type="checkbox" name="memberPass" class="pass-checkbox-input pass-checkbox-memberPass" checked="checked">*/
WebElement checkBox=driver.findElement(By.id("TANGRAM__PSP_8__memberPass"));
boolean isSelected=checkBox.isSelected();
9、getTagName()获取元素的标记名称
String tagName=byName.getTagName();
10、isEnabled()用于存储input等元素的可编辑状态,例如:文本框、复选框、单选框;返回true(可编辑)或false(不可编辑)
boolean enabled=checkBox.isEnabled();
11、getAttribute()用于获取指定属性的值
String btnValue=byLoginButton.getAttribute("value");
12、窗口最大化
driver.manage().window().maximize();
13、accept()方法是单击弹出的对话框的确认按钮,例如:Alert,Confirmation,Prompt
driver.switchTo().alert().accept();
14、dismiss()方法实现单击弹出对话框的取消按钮;
driver.switchTo().alert().dismiss();
15、getText()获取弹出对话框的文本内容
driver.switchTo().alert().getText();
16、获取当前cookie的集合
Set<Cookie> cookie=driver.manage().getCookies();
17、refresh()页面刷新
driver.navigate().refresh();
相关文章推荐
- java学习笔记之ORM注解
- Deep Learning(深度学习)学习笔记整理系列之(四)
- 大道至简阅读笔记02
- 【转】Linux CentOS内核编译:下载CentOS源码、编译2.6.32-220的错误(apic.c:819 error 'numi_watchdog' undeclared)
- android 多渠道打包
- 数据结构(树,点分治):POJ 1741 Tree
- 跳出多重循环 JS
- BZOJ3245 最快路线
- Deep Dive 3 - NIO
- 学习进度条--第十六周
- 「C语言」单链表/双向链表的建立/遍历/插入/删除
- appium启动sdk的android模拟器
- 【C语言】22-枚举
- LightOj1294 Positive Negative Sign
- 时序图
- C/C++ 字符串操作函数 思维导图梳理
- thinkphp3.2【路由解析】
- MAC系统安装rz sz方法
- 流程控制-->foreach语句
- 靠前IT公司实习两月谈