求知 文章 文库 Lib 视频 iPerson 课程 认证 咨询 工具 讲座 Model Center   Code  
会员   
要资料
 
 

Selenium教程
Selenium概述
Selenium IDE
Selenium IDE下载
Selenium IDE 工具特点
Selenium IDE测试创建
Selenium IDE测试
Selenium IDE验证点
Selenium - IDE模式匹配
Selenium用户扩展
Selenium IDE- 不同的浏览器
Selenium 环境安装设置
Selenium RC
Selenium - Selenese命令
Selenium Webdriver
Selenium定位器
文本框的相互作用
单选按钮互动
复选框交互
下拉框交互
Synchronization 同步
拖放
键盘操作
鼠标操作
多选择操作
查找所有链接
Selenium测试设计技术
Selenium页面对象模型
使用Excel数据驱动
log4j日志
异常处理
多浏览器测试
捕捉屏幕截图
捕捉视频
Selenium TestNG
Selenium网格
 
 

多选择操作
936 次浏览
3次  

多选择操作

有时,我们会在一个情况来选择列表框或文本区域中两个或多个项目。要理解一样,我们会demostrate多个选择从列表中使用“http://demos.devexpress.com
/aspxeditorsdemos/ListEditors/MultiSelect.aspx”。

例子

我们要从该列表中选择3个项目,如下图所示:

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.Action;

public class webdriverdemo
{
public static void main(String[] args) throws InterruptedException
{
WebDriver driver = new FirefoxDriver();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.navigate().to("http://demos.devexpress.com
/aspxeditorsdemos/ListEditors/MultiSelect.aspx");
//driver.manage().window().maximize();

driver.findElement(By.id("ContentHolder_lbSelectionMode
_I")).click();
driver.findElement(By.id("ContentHolder_lbSelectionMode
_DDD_L_LBI1T0")).click();

Thread.sleep(5000);

// Perform Multiple Select
Actions builder = new Actions(driver);
WebElement select = driver.findElement(By.id("ContentHolder
_lbFeatures_LBT"));
List<WebElement> options = select.findElements(By.
tagName("td"));
System.out.println(options.size());
Action multipleSelect = builder.keyDown(Keys.CONTROL)
.click(options.get(2))
.click(options.get(4))
.click(options.get(6))
.build();
multipleSelect.perform();

driver.close();

}
}

输出

当执行脚本,如上面显示的项目将被选中,在列表框的大小也将被打印在控制台上。


您可以捐助,支持我们的公益事业。

1元 10元 50元





认证码: 验证码,看不清楚?请点击刷新验证码 必填



936 次浏览
3次
 捐助