gpt4 book ai didi

java - Selenium Webdriver 多选下拉列表 ElementNotVisibleException

转载 作者:行者123 更新时间:2023-12-01 09:36:01 35 4
gpt4 key购买 nike

尝试从多选下拉框中进行选择,发现似乎是一个不错的资源。

我正在研究http://preview.harriscountyfws.org/我正在尝试在“按机构选择”多选下拉列表中选择多个项目。

我在这里向您展示的逻辑非常简单,并且遵循我找到的文章(如下所示),但我得到了 WebDriverException: Cannot click on option element。

对于获得有效的逻辑有什么建议吗?

逻辑如下:

WebElement we;
String searchText;
WebDriver driver;
Select select;
WebElement listbox_element;
listbox_element = driver.findElement(By.cssSelector("span[aria-owns='ddlRegion_listbox']"));
listbox_element.click();

driver = new FirefoxDriver();
driver.get("http://preview.harriscountyfws.org/");

searchText="ALL";
we = driver.findElement(By.id("ddlRegion"));
select = new Select(we);
select.selectByVisibleText(searchText);

引用号:http://www.techbeamers.com/dropdown-and-multiple-select-in-webdriver

最佳答案

我认为您没有找到正确的选择元素。您正在尝试的状态不是可见状态而是隐藏状态(可见:无)。

您需要找到“按机构搜索”下拉列表的箭头,找到该元素并单击它以使下拉列表可见。我不确定是否在 xpath 中包含 aria-owns 属性,但这是简单的方法。你可以看一下。

"//div[@id='searchDiv']//span[@aria-owns='ddlRegion_listbox']//span[@class='k-select']"

然后您需要等待 div[@id='regionSelectPopup'] 可见。将其粘贴到具有预期可见性条件的网络驱动程序等待中。

然后你可以在div中选择你想要的选项。我已经为所有人做了。您需要对其进行参数化。单击它。

"//div[@id='regionSelectPopup']//label[.='ALL']/preceding-sibling::input[@type='checkbox']"

它也可能适用于标签,但找不到复选框。

希望这能起作用。

        WebDriver driver = new FirefoxDriver();             
driver.manage().window().maximize();

driver.get("http://preview.harriscountyfws.org/");

WebElement agencySearchSelect = driver.findElement(
By.xpath("//div[@id='searchDiv']//span[@aria-owns='ddlRegion_listbox']//span[@class='k-select']"));

agencySearchSelect.click();

new WebDriverWait(driver, 3, 100).until(ExpectedConditions.visibilityOfElementLocated(
By.id("regionSelectPopup")));

WebElement agencyOption = driver.findElement(
By.xpath("//div[@id='regionSelectPopup']//label[.='ALL']/preceding-sibling::input[@type='checkbox']"));

agencyOption.click();

关于java - Selenium Webdriver 多选下拉列表 ElementNotVisibleException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38921826/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com