• 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         }
  • 相关阅读:
    MySQL自定义函数 1418报错
    MySQL存储过程查询
    MySQL存储过程---游标
    MySQL存储过程---流程控制(循环)
    MySQL存储过程---流程控制(分支)
    设计模式——单例模式
    准备写一个 四川票务网的 检测票自动买汽车票功能,结果登录不上悲伤,继续研究
    python批量下载微信好友头像,微信头像批量下载
    arduino 522样本中文注释
    zabbix服务的部署
  • 原文地址:https://www.cnblogs.com/qianjinyan/p/8990656.html
Copyright © 2020-2023  润新知