无法使用"选择"从下拉列表中选择,获取元素不可见异常

时间:2017-07-14 19:04:42

标签: java selenium select

我正在尝试从下拉列表中选择一些值并尝试所有选项:selectByIndex,selectByVisibleText,selectByValue但我无法在页面上选择值;尝试了不同的等待,但仍然得到以下错误:

Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: 
Element is not visible (WARNING: The server did not provide any stacktrace 
information)
Command duration or timeout: 42 milliseconds
Build info: version: '3.0.0-beta3', revision: 'c7b525d',  os.name: 'Windows 
10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, 
appBuildId=20160726073904, version=, platform=XP, proxy={}, command_id=1, 
specificationLevel=0, acceptSslCerts=false, browserVersion=48.0, 
platformVersion=10.0, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, 
browserName=Firefox, takesScreenshot=true, takesElementScreenshot=true, 
platformName=Windows_NT, device=desktop}]
Session ID: 83d79d14-527d-4a8e-a05e-01671d7b73f3
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:631)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:284)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at org.openqa.selenium.support.ui.Select.setSelected(Select.java:324)
at org.openqa.selenium.support.ui.Select.selectByValue(Select.java:201)
at accessingForms.FormElements.main(FormElements.java:39)

以下是我的代码片段,firefox版本48

    driver.get("http://newtours.demoaut.com");
    WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("userName")));     
    driver.findElement(By.partialLinkText("here")).click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("country")));
    System.out.println("wait statement executed");
 Select CountryDrpDwn = new Select(driver.findElement(By.name("country")));
    System.out.println("found the drop down");      
    Thread.sleep(1000);
    CountryDrpDwn.selectByValue("3");
    System.out.println("Selected by value mofo");
    Thread.sleep(2000);
    CountryDrpDwn.selectByVisibleText("ANTARCTICA ");
    System.out.println("Antarctica Selected");

提前感谢您的帮助

0 个答案:

没有答案