0

I need to select a value from drop-down, which has javascript. Any help is highly appreciated!

Following HTML:

<div class="popupMenuButton">
 <a id="_sawrl" bh="PML" _mid="_g7yog" class="awmenuLink" style="text-decoration:none" href="#">
 <nobr>
 FORMALIN VAPO TABS
 <img width="15" height="17" align="absmiddle" border="0" style="margin-bottom:1px;" src="/EasyCare-2.0/AribaWeb/ad/content/AWXDebugResourceActions/13/en_US/widg/arrowcolor.gif" alt="">
 </nobr>
 </a>
</div>

Java code

WebElement dropDownListBox = waitById("_sawrl");
Select clickThis = new Select(dropDownListBox);
clickThis.selectByVisibleText("FORMALIN VAPO TABS")

Exception

Exception in thread "main" org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "a"
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:30'
System info: host: , os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_51'
Driver info: driver.version: unknown
 at org.openqa.selenium.support.ui.Select.<init>(Select.java:46)
 at ui.stores.UIMaterialRecepit.setBrandName(UIMaterialRecepit.java:71)
 at tc.stores.TCMaterialRecepit.receiveMaterial(TCMaterialRecepit.java:32)
 at tc.StartAutmation.main(StartAutmation.java:48)
Cerbrus
73.2k19 gold badges137 silver badges151 bronze badges
asked Oct 17, 2014 at 6:59

3 Answers 3

1

As the exception says:

Element should have been "select" but was "a".

Your dropDownListBox is an anchor element. (<a id="_sawrl"...).
new Select() only accepts <select> elements.

answered Oct 17, 2014 at 7:04
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for the response. Can you please add some light on selenium code?
I don't know anything about selenium. I'm just interpreting the error here.
Is it possible to see the behaviour of the website? Or maybe you could describe it? As Cerbrus mentioned, "new Select()" only accepts <select>-Elements. How does the anchor element react? Do you need to click it? Or maybe it just needs a mouseover-event?
@Mathhias Anchor element react here by clicking the element. Indeed, it has list of elements. FYI, this application is in aribaweb. Please let me know if I need to add anything on the same.
0

As said by Cerbrus, your element is not a real select. You can handle such stuff by clicking.

Say, your 'select' looks like:

<div class="menubox-select AFGFLKJV">
 <div class="menuItem" row="1" >Info</div>
 <div class="menuItem" row="2" >Stuff</div>
 <div class="menuItem" row="3" >Teddy Bears</div>
</div>

Then, in order to select:

driver.findElement(By.xpath("//div[contains(@class, 'menubox-select')]").findElement(By.xpath(".//*[contains(text(), 'Stuff')]").click();

That's quite a usual thing for custom selectboxes. You can, however, omit using element.findElement. Still before clicking an option you need to trigger options to be visible, otherwise you get exception.

answered Oct 17, 2014 at 9:40

Comments

0

I was able to figure out the problem. Thank you @Cerbrus and @TEH for the pointers.

Following is the java code:

driver.findElement(By.xpath("//*[@id='_sawrl']").click();
driver.findElement(By.xpath("//*[@id='_immwib']").click();
answered Oct 17, 2014 at 13:40

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.