1

enter image description here

I need to automate the selection for a drop down box in selenium. The html code which comprises the dropdown is given below. The html code for each component is taken using firebug.

// Input Area
<input type="text" title="Filter by Administrator" readonly="readonly" value="Filter by Administrator" id="dnn_ctr373_View_BusinessList_admin_dd_Input" class="rcbInput rcbEmptyMessage" name="dnn$ctr373$View$BusinessList_admin_dd" autocomplete="off">
// Dropdown arrow
<a style="overflow: hidden;display: block;position: relative;outline: none;" id="dnn_ctr373_View_BusinessList_admin_dd_Arrow">select</a>
// Values inside drop down
<ul class="rcbList" style="list-style:none;margin:0;padding:0;zoom:1;">
<li class="rcbItem ">All</li>
<li class="rcbItem ">[email protected]</li>
<li class="rcbHovered ">[email protected]</li>
</ul>

I use the following code for automating the dropdown selection, based on the reply from here.

Select select = new Select(driver.findElement(By.xpath("//*[@id=\"dnn_ctr373_View_BusinessList_admin_dd_Input\"]")));
select.deselectAll();
select.selectByVisibleText("All");

The code gives me the following exception:

org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "input"
Build info: version: '2.28.0', revision: '18309', time: '2012-12-11 20:21:18'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.35-32-generic', java.version: '1.6.0_26'
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.Select.<init>(Select.java:46)
at FilterByAdministrator.testFilterByAdministrator(FilterByAdministrator.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod1ドル.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner3ドル.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner1ドル.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access000ドル(ParentRunner.java:53)
at org.junit.runners.ParentRunner2ドル.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

I am not sure, whether the code I used above for dropdown selection is correct or not.

Can someone please let me know the possible solution for the same.

asked Apr 9, 2013 at 11:18
0

5 Answers 5

3

Try this:

driver.findElement(By.xpath("//*[text()='select']")).click();
driver.findElement(By.xpath("//*[text()='All']")).click();

It might work. As per your html it's not looking like a select box. You may achieve it with normal click operations.

answered Apr 10, 2013 at 11:46
Sign up to request clarification or add additional context in comments.

1 Comment

Above lines with case sensitive touchup Driver.Instance.FindElement(By.XPath("//*[text()='select']")).Click(); Driver.Instance.FindElement(By.XPath("//*[text()='All']")).Click();
2

Use:

driver.findElement(By.id("dnn_ctr373_View_BusinessList_admin_dd_Input"));

Instead of:

driver.findElement(By.xpath("//*[@id=\"dnn_ctr373_View_BusinessList_admin_dd_Input\"]")));

EDIT

Try the below code and let me know if it is working.

WebElement DropDown = driver.findElement(By.id("dnn_ctr373_View_BusinessList_admin_dd_Input"));
Dropdown.sendKeys("All");
answered Apr 9, 2013 at 11:40

6 Comments

Check the EDIT in my answer and let me know if you are still facing the same issue.
maybe Dropdown.click will work better. And then you will have to find the elements shown in the dropdown.
seems it works ok now.. I will post my comment further after a detailed check and accept the answer. thanks for the help.
with the given code, though the exception is gone, it just highlights the "All" element in the drop down. A click on the drop down item is not happening. Also, though I change "All" to "[email protected]" which is the second value in the drop down, it still keep showing "All" as highlighted as shown by the image in the post.
Add Dropdown.sendKeys(Keys.ENTER); after Dropdown.sendKeys("All");
|
1

If you read the error message it says -

Element should have been "select" but was "input"

Which indicates that the web element in question is an input field type. So instead of selecting, try typing/send your input, like so

driver.findElement(By.id("dnn_ctr373_View_BusinessList_admin_dd_Input")).sendKeys("All");
answered Apr 9, 2013 at 12:48

1 Comment

this does not work either. The same issue I get as mentioned in the comment above for HemChe's answer
1

In python webdriver dropdown selection is very easiest way. See the below code.

Select(driver.find_element_by_xpath("xpath")).select_by_visible_text(" enter text with you want select")

It should be work in python selenium webdriver.

answered Apr 10, 2013 at 5:29

Comments

1

Above lines with case sensitive touchup

Driver.Instance.FindElement(By.XPath("//*[text()='select']")).Click();
Driver.Instance.FindElement(By.XPath("//*[text()='All']")).Click();
answered Feb 15, 2016 at 18:29

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.