wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("LOGON_selectedUser")));
WebElement mySelectElement = driver.findElement(By.id("LOGON_selectedUser"));
mySelectElement.click();
Select dropdown= new Select(driver.findElement(By.id("LOGON_selectedUser")));
dropdown.selectByVisibleText("HOTLINE-FAMILY SAFETY - Acting Supervisor");
下面是我得到的错误:
找不到带有以下文字的选项:热线-家庭安全-代理主管我试过了。价值比特没有运气。(
然而,我可以用语句myselectelelement .click()来选择下拉列表;但是当我尝试选择下拉菜单时,我总是无法找到元素。请帮助。
下面是DOM:
输入图片描述
这个网页是用Angular构建的。请尝试用Select class
诱导Explicit waits
Select dropdown = new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[@name='selectedUser' and @id='LOGON_selectedUser' and @onchange]"))));
dropdown.selectByIndex(1);
如果不行,下面的
应该可以((JavascriptExecutor) driver).executeScript("return document.getElementById('LOGON_selectedUser').selectedIndex = '" + index + "';)
其中index
是一个变量,尝试传递索引号,如1,2,3等…