gpt4 book ai didi

java - 无法从下拉列表中选择选项,导致 ElementNotVisibleException

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

import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class DellDropdown {

public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://www.dell.com/");
WebElement dropdown=driver.findElement(By.xpath("//select[@class='para_small']"));
Select select=new Select(dropdown);
select.selectByIndex(5);
List<WebElement> options=select.getOptions();
for(int i=0;i<options.size();i++)
{
options.get(i).getText();
}
}
}

我在 select.selectByIndex(5) 行遇到 ElementNotVisibleException,有人可以在这方面帮助我吗?

最佳答案

您可能必须等到下拉菜单实际可见,然后才能尝试选择选项:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[@class='para_small']")))

关于java - 无法从下拉列表中选择选项,导致 ElementNotVisibleException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22987586/

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