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.其实基于定 ...
随机推荐
- Linux vm运行参数 - OOM相关的参数
一.前言 本文是描述Linux virtual memory运行参数的第二篇,主要是讲OOM相关的参数的.为了理解OOM参数,第二章简单的描述什么是OOM.如果这个名词对你毫无压力,你可以直接进入第三 ...
- unity5, Configurable Joint: Anchor, Connected Anchor, Auto Configure Connected Anchor
configurable joint加在轮子上,connected body是车身. 这种情况下,Anchor=(0,0,0)表示轮子一端joint锚点取carWheelCenter Connecte ...
- Mybatis(四):MyBatis核心组件介绍原理解析和源码解读
Mybatis核心成员 Configuration MyBatis所有的配置信息都保存在Configuration对象之中,配置文件中的大部分配置都会存储到该类中 SqlSession ...
- SpringCloud 分布式配置
转 http://www.cnblogs.com/zhangjianbin/p/6347247.html 前言 在单体式应用中,我们通常的做法是将配置文件和代码放在一起,这没有什么不妥.当你的应用变得 ...
- μCOS-II系统之事件(event)的使用规则及Semaphore实例
**************************************************************************************************** ...
- Jquery获得子页面中某个元素
本页面中有子框架iframe1.获取iframe1中元素 $("input[name$='svNo']", window.frames["iframe1"].d ...
- python @property使用详解
1.@property,@xx.setter的作用把方法变成属性@property获取属性@xx.setter设置属性 2.使用示例 #@property使用 class Lang(object): ...
- 封装一个音乐列表music-list基础组件,可以共用,哪个需要的时候就是哪个props相应的值
1.封装music-lsit组件: <template> <div class="music-list singer-detail"> <div cl ...
- android从Dialog对话框中取得文本文字
android中Dialog对话框获取文本文字,只需要使用editor的getText方法就可以获得,示例如下:final EditText et = new EditText(this); et.s ...
- ld,连接器
连接器的功能,是将一个可执行程序所需的目标文件和库文件最终整合为一体.一个程序通常包含传统的三个段,.test, .data, .bss段.连接器的功能就是将各个目标文件个库文件中的三个段进行合并. ...