zoukankan      html  css  js  c++  java
  • Xpath入门

    selenium webdriver学习(八)------------如何操作select下拉框

    http://blog.sina.com.cn/s/blog_71a536990101azot.html


    下面我们来看一下selenium webdriver是如何来处理select下拉框的,以http://passport.51.com/reg2.5p这个页面为例。这个页面中有4个下拉框,下面演示4种选中下拉框选项的方法。select处理比较简单,直接看代码吧:) 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 SelectsStudy { public static void main(String[] args) { // TODO Auto-generated method stub System.setProperty("webdriver.firefox.bin","D:\\Program Files\\Mozilla Firefox\\firefox.exe"); WebDriver dr = new FirefoxDriver(); dr.get("http://passport.51.com/reg2.5p"); //通过下拉列表中选项的索引选中第二项,即2011年 Select selectAge = new Select(dr.findElement(By.id("User_Age"))); selectAge.selectByIndex(2); //通过下拉列表中的选项的value属性选中"上海"这一项 Select selectShen = new Select(dr.findElement(By.id("User_Shen"))); selectShen.selectByValue("上海"); //通过下拉列表中选项的可见文本选中"浦东"这一项 Select selectTown = new Select(dr.findElement(By.id("User_Town"))); selectTown.selectByVisibleText("浦东"); //这里只是想遍历一下下拉列表所有选项,用click进行选中选项 Select selectCity = new Select(dr.findElement(By.id("User_City"))); for(WebElement e : selectCity.getOptions()) e.click(); } } 从上面可以看出,对下拉框进行操作时首先要定位到这个下拉框,new 一个Selcet对象,然后对它进行操作。 INFO comes from :http://jarvi.iteye.com/blog/1450883

      

  • 相关阅读:
    SAP HANA概述——SAP HANA学习笔记系列
    如何在Visual Studio 2010中使用CppUTest建立TDD的Code Kata的环境
    客户旅程分析 Customer Journey Mapping
    “用户故事”来做展会——敏捷嘉年华(敏捷之旅2012上海站)经验分享
    相机翻拍书本
    外网访问路由
    新编全医药学大词典下载地址
    MKV声道切换花屏处理
    几何画板动态表达式(文本与变量合并)
    修改IP地址
  • 原文地址:https://www.cnblogs.com/qmfsun/p/3130851.html
Copyright © 2011-2022 走看看