zoukankan      html  css  js  c++  java
  • Java编程语言下Selenium 对于下拉框,单选,多选等选择器的操作

     1 WebElement selector = driver.findElement(By.id("Selector"));
     2         Select select = new Select(selector);
     3         select.selectByIndex(3);
     4         select.selectByVisibleText("桃子");
     5         select.selectByValue("apple");
     6 
     7         System.out.println(select.getAllSelectedOptions().toString());
     8         Thread.sleep(10000);
     9         WebElement showSelectResult = driver.findElement(By.name("showSelectResult"));
    10         showSelectResult.click();
    11         Thread.sleep(10000);
    12         Alert yourSelect = driver.switchTo().alert();
    13         Assert.assertTrue(yourSelect.getText().contains("苹果"));
    14         Thread.sleep(10000);
    15         yourSelect.accept();
    16 
    17         // for radio Box
    18 
    19         WebElement duRadioBox = driver.findElement(By.cssSelector("div#radio>input.Baidu"));
    20         WebElement aLiRadioBox = driver.findElement(By.cssSelector("div#radio>input.Alibaba"));
    21         WebElement TXRadioBox = driver.findElement(By.cssSelector("div#radio>input.Tencent"));
    22         WebElement MiRadioBox = driver.findElement(By.cssSelector("div#radio>input.Mi"));
    23         Thread.sleep(10000);
    24         Assert.assertTrue(TXRadioBox.isSelected());
    25         Assert.assertTrue(!MiRadioBox.isEnabled());
    26         Thread.sleep(10000);
    27 
    28         try {
    29 
    30             if (duRadioBox.isEnabled()) {
    31                 duRadioBox.click();
    32                 System.out.println("元素被点击");
    33             }
    34         } catch (Exception e) {
    35 
    36             System.out.println("点击元素失败。" + e.toString());
    37         }
    38 
    39         Assert.assertTrue(duRadioBox.isSelected());
    40         System.out.println(duRadioBox.isSelected());
    41         Thread.sleep(10000);
    42 
    43         aLiRadioBox.click();
    44         Assert.assertTrue(aLiRadioBox.isSelected());
    45         Thread.sleep(10000);
    46 
    47         // for checkBox
    48 
    49         List<WebElement> webCheckBox = driver.findElements(By.xpath("//input[@type='checkbox']"));
    50 
    51         for (WebElement e : webCheckBox) {
    52             e.click();
    53             Assert.assertTrue(e.isSelected());
    54             Thread.sleep(10000);
    55         }
  • 相关阅读:
    Toolbar Painter 工具条制作
    编程实现Windows瞬间关机
    如何在应用程序中修改本地环境变量
    据磁力链获得BT种子
    熟练使用NTFS的文件链接技术
    js中实现页面跳转
    keychain 多应用共享数据
    得到bundle seed id
    shell 基础 $(cd `dirname $0`;pwd)
    解决iOS应用内购买报错:invalidProductIdentifiers
  • 原文地址:https://www.cnblogs.com/qianjinyan/p/8990656.html
Copyright © 2011-2022 走看看