14-基本控件的调用

1.输入框input

(1)元素标记

<input id="user" type="text">

(2)主要操作

  • driver.findElement(By.id("user")).sendKeys("test");

sednKeys代表输入,参数为要输入的值

  • driver.findElement(By.id("user")).clear();

clear代表清除输入框中原有的数据

2.超链接a

(1)元素标记

<a class="baidu" href="http://www.baidu.com">baidu</a>

(2)主要操作

  • driver.findElement(By.xpath("//div[@id="link"]/a")).click();

click代表点击这个a链接

3.下拉菜单select

(1)元素标记

<select name="select">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
(2)主要操作

 

4.单选radiobox

(1)元素标记

 <input class="Volvo" type="radio" name="identity"/>

(2)主要操作

 

5.多选checkbox

(1)元素标记

<input type="checkbox" name="checkbox1"/>

(2)主要操作

6.按钮button

(1)元素标记

  在html中,按钮一般有两种表现形式。

  <input class="button" type="button" disabled="disabled" value="Submit">

  <button class="button" disabled="disabled">Submit</button>

(2)主要操作

 

7.Alert类

(1)表现形式

  Alert类,是指Windows弹窗的一些操作。

(2)主要操作

8.Action类

(1)表现形式

  一般是在要触发一些js函数或者一些js事件时,要用到这个类。

  <input class="over" type="button" onmouseout="mouseOut()" onmouseover="mouseOver()" value="Action"/>

(2)主要操作

9.上传文件操作
(1)元素标记
  <input id="load" type="file>
(2)主要操作
 
10.调用JS
(1)目标
  • 执行一段JS,来改变Html
  • 一些非标准控件无法用selenium2的API时,可以执行JS的办法来取代
(2)主要操作
 11.iframe操作
(1)表现形式
  在html中为<iframe width="800" height="330" frameborder="0" src="./demo1.html" name="aa">
(2)主要操作
12.多窗口切换
(1)表现形式
  在html中一般为<a class="open" target="_blank" href="http://www.baidu.com">open new window</a>
(2)主要操作
 
13.Wait机制
(1)目的
  让元素对象在可见后进行操作,取代Thread.sleep,使其变成智能等待
(2)主要操作
 
 
 
 
posted @ 2015-05-11 13:16  RunningYY  阅读(398)  评论(3)    收藏  举报