zoukankan      html  css  js  c++  java
  • Selenium下拉框自带方法使用详解。

    public void SelectOptionSelenium() {
    driver.get("https://www.imooc.com/user/setprofile");
    driver.findElement(By.className("js-edit-info")).click();//点击编辑按钮
    try {
    Thread.sleep(2000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    WebElement UserFrom = driver.findElement(By.id("profile"));//定位到from表单
    WebElement job = UserFrom.findElement(By.id("job"));//通过from表单定位到职位下拉框
    /**
    * 定位到下拉框后,select.selectByIndex()方法进行选择
    */
    Select select = new Select(job);
    select.selectByIndex(8);//根据下标选择
    try {
    Thread.sleep(2000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    select.selectByValue("1");//根据职位名称对应的value值选择
    try {
    Thread.sleep(2000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    select.selectByVisibleText("PHP开发工程师");//根据职位名称选择
    System.out.println(select.isMultiple());//判断下拉框是否是多选的
    // select.deselectByVisibleText("PHP开发工程师");//不选中这个方法针对的都是多选下拉框
    java.util.List<WebElement> SelectOption = select.getAllSelectedOptions();//获取到下拉框里面被选择的所有职位
    for (WebElement option : SelectOption) {
    System.out.println(option.getText());
    }
    driver.close();
    }

  • 相关阅读:
    [LeetCode] Contains Duplicate II
    [LeetCode] House Robber II
    [LeetCode] Permutations II
    [LeetCode] Permutations
    [LeetCode] Next Permutation
    谈谈套接字
    基于Linux系统的Nagios网络管理模块的实现
    Windows/Linux下磁盘使用的图形化工具简介
    利用日志使管理Linux更轻松
    实际感受美丽的Linux(多组视频)
  • 原文地址:https://www.cnblogs.com/wangffeng293/p/13823416.html
Copyright © 2011-2022 走看看