selenium测试(Java)--下拉框(二十一)
例子:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>calc</title>
<script>
function calcResult() {
var num1 = document.getElementById("id1").value;
var calctag = document.getElementById("id2").value;
var num2 = document.getElementById("id3").value;
var result = 0; switch (calctag) {
case "+":
result = parseInt(num1) + parseInt(num2);
break;
case "-":
result = parseInt(num1) - parseInt(num2);
break;
case "*":
result = parseInt(num1) * parseInt(num2);
break;
case "/":
if (parseInt(num2) == 0) {
alert("数字2不能为0");
} else {
result = parseInt(num1) / parseInt(num2);
}
break;
default:
alert("......");
} document.getElementById("id5").value = result; }
</script>
</head>
<body>
<form>
数字1:<input type="text" id="id1" name="num1" />
<select id="id2" name="calc">
<option value="+" selected="selected">加</option>
<option value="-">减</option>
<option value="*">乘</option>
<option value="/">除</option>
</select>
数字2:<input type="text" id="id3" name="num2" />
<input type="button" name="is" id="id4" value="=" onclick="calcResult()" />
结果:<input type="text" id="id5" name="result" />
</form>
</body>
</html>
代码:
package com.test.select; import java.util.Iterator;
import java.util.List; 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; public class SelectTest { public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("file:///D:/10-selenium/workspace/SeleniumTest/src/com/test/select/calc.html");
driver.manage().window().maximize(); driver.findElement(By.id("id1")).sendKeys("4"); Select sel = new Select(driver.findElement(By.name("calc")));
sel.selectByValue("/"); driver.findElement(By.id("id3")).sendKeys("2"); driver.findElement(By.id("id4")).click(); System.out.println(driver.findElement(By.id("id5")).getAttribute("value")); ////////////////////////////////////////////////////////////////
driver.findElement(By.id("id1")).clear();
driver.findElement(By.id("id1")).sendKeys("3"); Select sel2 = new Select(driver.findElement(By.name("calc")));
sel2.selectByValue("+"); driver.findElement(By.id("id3")).clear();
driver.findElement(By.id("id3")).sendKeys("1"); driver.findElement(By.id("id4")).click(); System.out.println(driver.findElement(By.id("id5")).getAttribute("value")); ////////////////////////////////////////////////////////////////
driver.findElement(By.id("id1")).clear();
driver.findElement(By.id("id1")).sendKeys("5"); Select sel3 = new Select(driver.findElement(By.name("calc")));
sel3.selectByValue("*"); driver.findElement(By.id("id3")).clear();
driver.findElement(By.id("id3")).sendKeys("6"); driver.findElement(By.id("id4")).click(); System.out.println(driver.findElement(By.id("id5")).getAttribute("value")); ////////////////////////////////////////////////////////////////
driver.findElement(By.id("id1")).clear();
driver.findElement(By.id("id1")).sendKeys("100"); Select sel4 = new Select(driver.findElement(By.name("calc")));
sel4.selectByValue("-"); driver.findElement(By.id("id3")).clear();
driver.findElement(By.id("id3")).sendKeys("1"); driver.findElement(By.id("id4")).click(); System.out.println(driver.findElement(By.id("id5")).getAttribute("value")); ////////////////////////////////////////////////////////////////////////////////
Select selall = new Select(driver.findElement(By.name("calc"))); List<WebElement> lw= selall.getOptions();
Iterator<WebElement> iterator = lw.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next().getAttribute("value"));
} driver.quit(); } }
结果:
4
99
+
-
*
/
selenium测试(Java)--下拉框(二十一)的更多相关文章
- 《手把手教你》系列技巧篇(三十二)-java+ selenium自动化测试-select 下拉框(详解教程)
1.简介 在实际自动化测试过程中,我们也避免不了会遇到下拉选择的测试,因此宏哥在这里直接分享和介绍一下,希望小伙伴或者童鞋们在以后工作中遇到可以有所帮助. 2.select 下拉框 2.1Select ...
- Python3 Selenium自动化-select下拉框
Python3 Selenium自动化-select下拉框 selenium介绍select下拉框相关的操作方法:
- Selenium+java - 下拉框处理
常见下拉框也分两种:一种是标准控件和非标准控件(一般为前端开发人员自己封装的下拉框),本篇文章中将重点讲解标准下拉框操作. 1.Select提供了三种选择某一项的方法 select.selectByI ...
- Java+selenium 如何定位下拉框select
场景:需要进行下拉选择定位元素. 一.select菜单 select也是比较常见的,selenium封装了以下方法, 创建select WebElement selector = dr ...
- python+selenium七:下拉框、选项框、select用法
# from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsimpo ...
- Selenium WebDriver-操作下拉框内容
操作下拉框中的内容 #encoding=utf-8 import unittest import time import chardet from selenium import webdriver ...
- java下拉框,滚动条
package com.soft.test; /** * 下拉列表.下拉框.滚动条的使用 */ import javax.swing.*; import java.awt.*; public clas ...
- 基于定位下拉框或者需要点击link才显示的下拉框,二次定位与多次定位实现的实际效果区别
还是基于上次那个练习的后续出现的思考,http://www.cnblogs.com/8013-cmf/p/6555790.html 界面: 源码: 写法如下: 继续解释这两种的区别: 1.其实基于定 ...
- selenium中的下拉框处理模块Select
在UI自动化测试过程中,经常会遇到一些下拉框,如果我们基于Webdriver操作的话就需要click两次,而且很容易出现问题,实际上Selenium给我们提供了专门的Select(下拉框处理模块). ...
- 百度“搜索设置”之基于定位下拉框或者需要点击link才显示的下拉框,二次定位与多次定位实现的实际效果区别
还是基于上次那个练习的后续出现的思考,http://www.cnblogs.com/8013-cmf/p/6555790.html 界面: 源码: 写法如下: 继续解释这两种的区别: 1.其实基于定 ...
随机推荐
- web项目,美工和前台配合,页面路径访问问题
一.美工写页面使用相对路径,但后台使用项目的应用绝对路径,访问时会出现404或页面乱码的问题 目前的解决方法:在页面中添加base标签,指定当前页面默认的路径 base标签:为页面上的所有链接规定默认 ...
- 群智能优化算法-测试函数matlab源码
群智能优化算法测试函数matlab源代码 global M; creatematrix(2); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %画ackley图. %%%% ...
- ubuntu中将某一程序设置为开机启动项的方法
一.简要说明 Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤. 加载内核LILO启动之后,如果你选择了Linux作为准备引导的操作系统,第一个被加载 ...
- ubuntu14中创建python虚拟环境
一.安装python-virtualenv包 sudo apt-get install python-virtualenv 安装完成后,创建一个虚拟环境文件夹. mkdir VENVcd VENV 创 ...
- Leaf——美团点评分布式ID生成系统
背景 在复杂分布式系统中,往往需要对大量的数据和消息进行唯一标识.如在美团点评的金融.支付.餐饮.酒店.猫眼电影等产品的系统中,数据日渐增长,对数据分库分表后需要有一个唯一ID来标识一条数据或消息,数 ...
- mysqld_safe与mysqld区别详解
mysqld_safe与mysqld区别,直接运行mysqld程序来启动MySQL服务的方法很少见,mysqld_safe脚本会在启动MySQL服务器后继续监控其运行情况,并在其死机时重新启动它. 用 ...
- C++11新特性应用--介绍几个新增的便利算法(用于排序的几个算法)
继续C++11在头文件algorithm中添加的算法. 至少我认为,在stl的算法中,用到最多的就是sort了,我们不去探索sort的源代码.就是介绍C++11新增的几个关于排序的函数. 对于一个序列 ...
- mysqldump 备份单个数据库
mysqldump -uemove -h xx.xxx.xx.xx -P7996 -p --databases dbname >dbname.sql
- Flink articles
http://ictlabs-summer-school.sics.se/2015/slides/flink-advanced.pdf http://henning.kropponline.de/20 ...
- 每日英语:Can Going In and Out of Air Conditioning Cause Colds?
For most people, summer involves numerous daily shifts between scorching outdoor heat and frosty air ...