例子:

<!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)--下拉框(二十一)的更多相关文章

  1. 《手把手教你》系列技巧篇(三十二)-java+ selenium自动化测试-select 下拉框(详解教程)

    1.简介 在实际自动化测试过程中,我们也避免不了会遇到下拉选择的测试,因此宏哥在这里直接分享和介绍一下,希望小伙伴或者童鞋们在以后工作中遇到可以有所帮助. 2.select 下拉框 2.1Select ...

  2. Python3 Selenium自动化-select下拉框

    Python3 Selenium自动化-select下拉框 selenium介绍select下拉框相关的操作方法:

  3. Selenium+java - 下拉框处理

    常见下拉框也分两种:一种是标准控件和非标准控件(一般为前端开发人员自己封装的下拉框),本篇文章中将重点讲解标准下拉框操作. 1.Select提供了三种选择某一项的方法 select.selectByI ...

  4. Java+selenium 如何定位下拉框select

    场景:需要进行下拉选择定位元素.   一.select菜单       select也是比较常见的,selenium封装了以下方法, 创建select WebElement selector = dr ...

  5. python+selenium七:下拉框、选项框、select用法

    # from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsimpo ...

  6. Selenium WebDriver-操作下拉框内容

    操作下拉框中的内容 #encoding=utf-8 import unittest import time import chardet from selenium import webdriver ...

  7. java下拉框,滚动条

    package com.soft.test; /** * 下拉列表.下拉框.滚动条的使用 */ import javax.swing.*; import java.awt.*; public clas ...

  8. 基于定位下拉框或者需要点击link才显示的下拉框,二次定位与多次定位实现的实际效果区别

    还是基于上次那个练习的后续出现的思考,http://www.cnblogs.com/8013-cmf/p/6555790.html 界面: 源码: 写法如下:  继续解释这两种的区别: 1.其实基于定 ...

  9. selenium中的下拉框处理模块Select

    在UI自动化测试过程中,经常会遇到一些下拉框,如果我们基于Webdriver操作的话就需要click两次,而且很容易出现问题,实际上Selenium给我们提供了专门的Select(下拉框处理模块). ...

  10. 百度“搜索设置”之基于定位下拉框或者需要点击link才显示的下拉框,二次定位与多次定位实现的实际效果区别

    还是基于上次那个练习的后续出现的思考,http://www.cnblogs.com/8013-cmf/p/6555790.html 界面: 源码: 写法如下:  继续解释这两种的区别: 1.其实基于定 ...

随机推荐

  1. Linux中断 - IRQ Domain介绍

    一.概述 在linux kernel中,我们使用下面两个ID来标识一个来自外设的中断: 1.IRQ number.CPU需要为每一个外设中断编号,我们称之IRQ Number.这个IRQ number ...

  2. Linux下C结构体初始化

    1.前言 今天在公司看一同事写的代码,代码中用到了struct,初始化一个struct用的是乱序格式,如下代码所示: typedef struct _data_t { int a; int b; }d ...

  3. 谈谈CListCtrl如何调整行高

    原文链接: http://blog.csdn.net/sstower/article/details/9094939 调整CListCtrl 行高通常有3种方法: 1.设定字体2.设定图片3.处理Me ...

  4. Pandas dataframe 与 Spark dataframe 的区别

    区别 :http://www.voidcn.com/article/p-wsqbotem-boa.html 获取列名的列表: DataFrame.columns.values.tolist()

  5. jenkins 执行ssh 远程linux执行命令

    1.远程机器编写脚本: 脚本名称为: /app/jboss/jboss-as/logs/ALL_SERVICE_STOP.sh 功能为:停止某个服务器某个目录下面的所有应用 #!/bin/bash p ...

  6. unity, 让主角头顶朝向等于地面法线(character align to surface normal)

    计算过程如下: 1,通过由主角中心raycast一条竖直射线获得主角所在处地面法线,用作主角的newUp. 注:一定要从主角中心raycast,而不要从player.transform.positio ...

  7. unity Input.GetAxis和Input.GetAxisRaw

    float h = Input.GetAxis("Horizontal") ;//h range from -1 to 1 float v = Input.GetAxis(&quo ...

  8. js正则匹配中文

    alert(/[\u4e00-\u9fa5]{4}/.test("司徒正美"))//true alert(/[\u4e00-\u9fa5]{4}/.test("司正美&q ...

  9. angular学习笔记(一)-入门案例

    入门实例: 一个购物车产品清单,可以自行改变数量,总价自动计算的小例子: 代码如下: <!DOCTYPE html> <html ng-app> <head> &l ...

  10. C++友元详解

    1.什么是友元在一个类A中,将类B声明为友元类,则类B可以访问类A的私有成员和保护成员.另外,也可以将函数声明为友元函数. 2.什么时候用到友元若不同的类之间某些共享数据成员,可以使用友元,简化类的设 ...