我爱编程

获取selenium元素

2018-03-09  本文已影响0人  发奋的三弟

转自: http://blog.csdn.net/Lily_XL/article/details/51702803

 /**id 

*  登录*/

WebElementbyName=driver.findElement(By.name("phone"));

WebElementbyLoginButton=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()获取当前网页的标题

Stringtitle=driver.getTitle();

      6、getCurrentUrl()获取当前网页的URL

Stringurl=driver.getCurrentUrl();

        7、getText()用于存储元素的文本值,例如纯文本、超链接等;

Stringtext=byName.getText();

        8、isSelected()用于存储复选框或单选框的勾选情况,返回true(勾选)或false(未勾选)

        /***/

WebElementcheckBox=driver.findElement(By.id("TANGRAM__PSP_8__memberPass"));

booleanisSelected=checkBox.isSelected();

 9、getTagName()获取元素的标记名称

StringtagName=byName.getTagName();

 10、isEnabled()用于存储input等元素的可编辑状态,例如:文本框、复选框、单选框;返回true(可编辑)或false(不可编辑)

booleanenabled=checkBox.isEnabled();

 11、getAttribute()用于获取指定属性的值

StringbtnValue=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的集合

Setcookie=driver.manage().getCookies();

   17、refresh()页面刷新

driver.navigate().refresh();

上一篇下一篇

猜你喜欢

热点阅读