我是selenium的新学员,并尝试点击下拉列表来填充列表,但它继续给我运行时异常:
线程中的异常" main" org.openqa.selenium.ElementNotVisibleException: 元素当前不可见,因此可能无法与之互动
请帮忙。下面是我正在执行的代码。
WebDriver dr=new FirefoxDriver();
dr.get("https://jqueryui.com/selectmenu/");
dr.manage().window().maximize();
dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
dr.switchTo().frame(dr.findElement(By.className("demo-frame")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("speed- menu"))).click();
答案 0 :(得分:0)
要点击下拉列表Select a speed
,这里是您自己的代码,只需进行少量更改:
System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");
WebDriver dr=new FirefoxDriver();
dr.get("https://jqueryui.com/selectmenu/");
dr.manage().window().maximize();
dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
dr.switchTo().frame(dr.findElement(By.className("demo-frame")));
dr.findElement(By.xpath("//*[@id='speed-button']/span[@class='ui-selectmenu-text']")).click();
如果这回答你的问题,请告诉我。
答案 1 :(得分:0)
试试这个
WebDriver driver = new FirefoxDriver();
driver.get("https://jqueryui.com/selectmenu/");
WebElement DynamicElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.id("DynamicElement")));
OR
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("yourid")));