Reputation: 14738
I am trying force the ChromeDriver to select an item from the select box. However its failing on the line
Options = select.getOptions();
Strange is, that in below code, the getText();
method prints out all items in the select:
productChoooser.getText() = ...
BASE 2013
BASE 2014
but still I get exception... Code which is trying to click the item in select box:
List<WebElement> Options;
WebElement productChoooser = driver.findElement(By.id("mainForm:aucPanelId:1:product"));
System.out.println("productChoooser.getText() = " + productChoooser.getText());
Select select = new Select(productChoooser);
Options = select.getOptions();
String product = "BASE 2013";
for (WebElement option:Options){
System.out.println("option.getText() = " + option.getText());
if(option.getText().equals(product)){
option.click();
}
}
Does anyone know how to avoid it? I tried to update the Chrome and chromedriver.exe
to the newest version, but without any success...
Stack Trace:
org.openqa.selenium.WebDriverException: (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 47 milliseconds Build info: version: '2.16.1', revision: '15405', time: '2012-01-05 12:30:12' System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_20' Driver info: driver.version: RemoteWebDriver at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:147) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:113) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:435) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:231) at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:161) at org.openqa.selenium.remote.RemoteWebElement.findElementsByTagName(RemoteWebElement.java:227) at org.openqa.selenium.By$ByTagName.findElements(By.java:313) at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:146) at org.openqa.selenium.support.ui.Select.getOptions(Select.java:70) at com.deutscheboerse.testing.RegulationTest.selectProduct(RegulationTest.java:53) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.junit.runner.JUnitCore.run(JUnitCore.java:157) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:199) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Upvotes: 0
Views: 829
Reputation: 1559
WebElement select = webDriver.findElement(selector);
List<WebElement> optionList = select.findElements(By.tagName("option"));
for (WebElement option : optionList) {
if (option.getText().trim().equalsIgnoreCase("your value")) {
option.click();
break;
}
}
Upvotes: 1