繁体   English   中英

用于列表框选择的Selenium Java代码在Chrome和IE上有效,但在Firefox上不起作用

[英]Selenium Java code for Listbox selection works on Chrome and IE, but not Firefox

我正在一个公共网站上工作: http : //preview.harriscountyfws.org/

我正在尝试做一些简单的事情:从下拉列表中选择一个选项。

在IE和Chrome上运行的代码完全相同,在Firefox上失败。 没有错误产生。 它只是没有从“网站类型”下拉列表中选择正确的选项(“频道状态”)。

任何对此的帮助表示赞赏!

WebElement listbox_element2, we2;
        String ariaOwns = "siteType_listbox";
        String searchText2 = "Channel Status";


    listbox_element2 = driver.findElement(By.cssSelector("span[aria-owns='" + ariaOwns + "']"));
    listbox_element2.click();
    Sleep(2000);
    we2 = driver.findElement(By.xpath("//li[text()='" + searchText2 + "']"));
    if (we2 != null) {
        we2.click();
    }`

您可能希望引入一个明确的等待,同时在firefox浏览器上运行测试,然后打印所有下拉选项作为调试的一部分。 通过使用selectByValue(value)方法,可以从下拉列表中选择一个项目。

WebElement mySelectElement = driver.findElement(By.id("mySelect"));
Select dropdown= new Select(mySelectElement);
List options = dropdown.getOptions();
for (WebElement option : options) {
System.out.println(option.getText()); //output "option1", "option2", "option3"
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM