zoukankan      html  css  js  c++  java
  • 12.selenium之下拉框选择

    搜索下拉框实现代码如下:

    <select id="nr" name="NR">
      <option value="10" selected>每页显示 10 条</option>
      <option value="20">每页显示 20 条</option>
      <option value="50">每页显示 50 条</option>
    <select>
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.support.ui.Select;
     
     
    public class SelectDemo {
     
      public static void main(String[] args) throws InterruptedException {
     
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.baidu.com");
     
        driver.findElement(By.linkText("设置")).click();
        driver.findElement(By.linkText("搜索设置")).click();
        Thread.sleep(2000);
     
        //<select>标签的下拉框选择
        WebElement el = driver.findElement(By.xpath("//select"));
        Select sel = new Select(el);
        sel.selectByValue("20");
        Thread.sleep(2000);
     
        driver.quit();
      }
    }

    Select类用于定位select标签。 selectByValue()方法符用于选取<option>标签的value值。

  • 相关阅读:
    hdu 1392 凸包周长
    hdu 1847
    时间管理101招
    祝大家端午节快乐
    激励员工的二十种非经济手段
    Web2.0个人桌面
    回顾Windows系列的OEM版本历史
    什么是电子商务
    解析3G软件人才成功之道
    成功者应具备的八个心态
  • 原文地址:https://www.cnblogs.com/peiminer/p/13564913.html
Copyright © 2011-2022 走看看