selenium2.0处理case实例(一)
通过自动化脚本, 判断下拉框选项值是否按照字母顺序(忽略大小写)显示
case场景如下:
1)打开www.test.com;
2)判断下拉框选项是否按照字母顺序排列(忽略大小写)
3)选择其中一个任意选项, 并判断已经选中
4)提交表单,验证弹出alert,并且验证提示内容为“successfully”
页面的html代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function submit_confirm(){
alert("successfully");
}
</script>
</head>
<body>
<form name="selectOption" id="form1">
<select id="select1">
<option>American</option>
<option>china</option>
<option>Chinese</option>
<option>England</option>
<option>France</option>
</select>
<input type="submit" id="submit" value="submit" onclick="submit_confirm()">
</form>
</body>
</html>
完整的可运行的脚本如下:
package mavenSelenium; import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait; public class TestSelect extends Assert {
WebDriver driver;
WebDriverWait wait; @Before
public void init(){
driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
} @Test
public void test(){
//1、打开浏览器
driver.get("http://localhost:8080/myWebSite/test.html");
List<WebElement> elements=driver.findElements(By.xpath("//select[@id='select1']/option")); String[] s = new String[elements.size()];
int i=0;
for(WebElement element:elements){
System.out.println(element.getText());
s[i]=element.getText();
i++;
}
//2、验证是否按照字母顺序排列, 不区分大小写
for(int j=0;j<s.length-1;j++){
String temp1=s[j].toLowerCase();
String temp2=s[j+1].toLowerCase();
System.out.println("temp1="+temp1);
for(int k=0;k<temp1.length()&&k<temp2.length();k++){
System.out.println("temp1.charAt(k)="+temp1.charAt(k));
System.out.println("temp2.charAt(k)="+temp2.charAt(k));
if(temp1.charAt(k)<temp2.charAt(k)){
break;
}
if(temp1.charAt(k)>temp2.charAt(k)){
fail("the option is not in order");
}
}
}
//3、选中选项,并验证已选中
Select select=new Select(driver.findElement(By.id("select1")));//这里强转的话,会报类型转换错误,应以这种形式创建select
String selectText="Chinese";
select.selectByVisibleText(selectText);
assertEquals(selectText, select.getFirstSelectedOption().getText()); //4、提交表单,验证弹出alert,并且验证提示内容为“successfully”
driver.findElement(By.id("submit")).click();
Alert alert=driver.switchTo().alert();
assertEquals("successfully", alert.getText()); }
@After
public void tearDown(){
driver.quit();
}
}
selenium2.0处理case实例(一)的更多相关文章
- selenium2.0处理case实例(二)
本文通过具体代码处理过程, 来展示selenium中一些比较不常用的类的用法 1.javascriptExcutor,通过将driver强转成JavascriptExecutor类型, 调用execu ...
- Python版:Selenium2.0之WebDriver学习总结_实例1
Python版:Selenium2.0之WebDriver学习总结_实例1 快来加入群[python爬虫交流群](群号570070796),发现精彩内容. 实属转载:本人看的原文地址 :http:/ ...
- selenium2.0 处理各种窗口问题解决方法
selenium2.0处理muti-Windows . Frames .Popup Dialogs selenium2.0处理多窗口,弹窗等,只需要调用WebDriver 嵌套类:TargetLoca ...
- selenium1.0和selenium2.0页面等待处理详解
一.selenium1.0页面等待 1.……AndWait 经常会看到, selenium action命令中很多有这种……AndWait后缀, 例如click和clickAndWait命令: cli ...
- selenium win7+selenium2.0+python环境搭建
win7+selenium2.0+python环境搭建 by:授客 QQ:1033553122 步骤1:下载python 担心最新版的支持不太好,这里我下载的是python 2.7(selenium之 ...
- Oracle 11.2.0.4单实例打PSU,OJVM PSU补丁快速参考
写在前面: 1.Oracel打每个补丁的操作有时存在差异,所以不管多熟悉,都应该在打任何补丁之前阅读新补丁中附带的readme. 2.Oracle每季度都会更新一个最新的PSU,本文最新指的是当前最新 ...
- selenium2.0(WebDriver) API
1.1 下载selenium2.0的包 官方download包地址:http://code.google.com/p/selenium/downloads/list 官方User Guide: h ...
- 在selenium2.0中使用selenium1.0的API
Selenium2.0中使用WeDriver API对页面进行操作,它最大的优点是不需要安装一个selenium server就可以运行,但是对页面进行操作不如selenium1.0的Selenium ...
- selenium2.0的初步封装(java版本)
我们都知道, 在本地创建java项目后,引入selenium-java-2.35.0.jar selenium-support-2.35.0.jar junit-4.8.1.jar等等jar包之后 ...
随机推荐
- ActiveMQ, RabbitMQ和ZeroMQ 选型关注点
选择MQ时,主要关注的特性,可能就以下几个: 通信模式(是否满足业务场景): ActiveMQ: queue(producer/consumer), topic(publisher/subsriber ...
- apple mac 下使用机械键盘的办法,键盘映射工具软件,apple mac Mechanical keyboard
apple mac 下使用机械键盘的办法,键盘映射工具软件,apple mac Mechanical keyboard 想在苹果电脑 mac 系统下使用 机械键盘,大部分机械键盘不是为mac设计的,所 ...
- linux进程的几种状态
Linux是一个多用户,多任务的系统,可以同时运行多个用户的多个程序,就必然会产生很多的进程,而每个进程会有不同的状态. Linux进程状态:R (TASK_RUNNING),可执行状态. 只有在该状 ...
- 【解决】Oracle服务器ip地址被占用
数据库服务器ip地址被占用,怎么破?! 服务器: 1.改服务器ip: 2.改tnsnames.ora里配置的Oracle数据库ip: 3.重启Oracle服务: 客户端: 1.改tnsnames.or ...
- 安装 Linux 与 Windows 10 双系统,你需要了解的一切
该选Windows 10还是Linux Mint?鱼与熊掌当然可以兼得,但咱们得掌握点小技巧才能顺利搞定. Windows 10绝不是唯一一款值得我们安装在自己计算机之上的免费操作系统.Linux只靠 ...
- 成都Uber优步司机奖励政策(2月6日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- MSSQLSERVER数据库- 游标
游标是属于级行操作,遍历一个表一行一行读,而SQL查询是基于数据集的,在数据量大的时候,使用游标会降低查询速度.这是很明显的.但是有些操作就用游标实现.所以游标又是不或缺少的.我很久都没用游标了,一时 ...
- js 复制网页内容,兼容各浏览器
因需要做一个js单击,复制当前网页url的功能.使用的是如下的方法,但是只能在ie浏览器下正常使用. 方法如下: function copyURL(){ var clipBoardContent=&q ...
- 10409 - Die Game
Problem G: Die Game Life is not easy. Sometimes it is beyond your control. Now, as contestants of AC ...
- [React Native] Up and Running
We'll download the requirements for getting started with React Native, refactor our app to ES6, walk ...