0

你能请任何人告诉我我的代码有什么问题吗?

WebElement dropdown = driver.findElement(By.xpath("//*[@id='idCallType_100']"));
        List<WebElement> Options = dropdown.findElements(By.tagName("option"));       
        System.out.println(Options.size());       
        for(int i=0;i<Options.size();i++)
        {
            WebElement o = Options.get(i);
            System.out.println(Options.get(i).getText()+ " ---- " + Options.get(i).getAttribute("value"));
            driver.findElement(By.xpath("//*[@id='idInsertTaskButton']/a")).click();         **// I couldnt able to click on this line**
            Options.get(i).click();
            System.out.println("coming for email time");
            driver.findElement(By.xpath("//*[@id='idInsertTask_100']/div/div[1]/input")).click();   

        }

我正在尝试单击下拉菜单。对于第一次单击它的工作正常。下次它不从这一行执行时形成
Options.get(i).click(); 我不知道这里出了什么问题。

Thanks!
4

1 回答 1

0

只需将您的 WebElement 包装到 Select Object 中,如下所示

Select dropdown = new Select(driver.findElement(By.id("identifier")));

完成此操作后,您可以通过 3 种方式选择所需的值。考虑一个这样的 HTML 文件

<html>
<body>
<select id = "designation">
<option value = "MD">MD</option>
<option value = "prog"> Programmer </option>
<option value = "CEO"> CEO </option>
</option>
</select>
<body>
</html>

现在要识别下拉菜单

Select dropdown = new Select(driver.findElement(By.id("designation")));

要选择它的选项说'程序员'你可以做

dropdown.selectByVisibleText("Programmer ");

或者

dropdown.selectByIndex(1);

或者

dropdown.selectByValue("prog");

于 2013-08-28T13:26:02.497 回答