• 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();
    }

  • 相关阅读:
    linux 内核升级
    maven 热部署至tomcat
    Executor多线程框架使用
    数据库中的一些连接
    Ajax传统操作
    第三篇、简单的图片下载器
    第二篇、通过蓝牙连接外设
    第一篇、实现上拉和下拉刷新
    解决Git报错:The current branch is not configured for pull No value for key branch.master.merge found in configuration
    Spark核心概念
  • 原文地址:https://www.cnblogs.com/wangffeng293/p/13823416.html
Copyright © 2020-2023  润新知