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 ">dat@nykkos.com</li>
<li class="rcbHovered ">dat1@nykkos.com</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.FrameworkMethod$1.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.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.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.

Community
  • 1
  • 1
user1400538
  • 855
  • 5
  • 24
  • 42

5 Answers5

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.

user2087450
  • 339
  • 1
  • 11
  • Above lines with case sensitive touchup Driver.Instance.FindElement(By.XPath("//*[text()='select']")).Click(); Driver.Instance.FindElement(By.XPath("//*[text()='All']")).Click(); – Kurkula Feb 15 '16 at 18:29
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");
HemChe
  • 2,249
  • 1
  • 21
  • 33
  • Check the EDIT in my answer and let me know if you are still facing the same issue. – HemChe Apr 09 '13 at 12:37
  • maybe `Dropdown.click` will work better. And then you will have to find the elements shown in the dropdown. – Pavel Janicek Apr 09 '13 at 12:39
  • seems it works ok now.. I will post my comment further after a detailed check and accept the answer. thanks for the help. – user1400538 Apr 09 '13 at 12:52
  • 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 "dat@nykkos.com" which is the second value in the drop down, it still keep showing "All" as highlighted as shown by the image in the post. – user1400538 Apr 10 '13 at 04:53
  • Add `Dropdown.sendKeys(Keys.ENTER);` after `Dropdown.sendKeys("All");` – HemChe Apr 10 '13 at 05:18
  • basically Dropdown.sendKeys is not working as I mentioned above, since instead of "All" no matter what other value I provide as input , it is not getting selected/highlighted – user1400538 Apr 10 '13 at 06:40
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");
Amey
  • 8,470
  • 9
  • 44
  • 63
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.

Kv.senthilkumar
  • 936
  • 2
  • 16
  • 29
1

Above lines with case sensitive touchup

Driver.Instance.FindElement(By.XPath("//*[text()='select']")).Click();
Driver.Instance.FindElement(By.XPath("//*[text()='All']")).Click();
Kurkula
  • 6,386
  • 27
  • 127
  • 202