我尝试从下拉列表中选择一些值,并尝试了所有选项: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)
下面是我的代码片段,Firefox48版
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");
提前谢谢你的帮助
暂无答案!
目前还没有任何答案,快来回答吧!