0

I am new to selenium , currently I am working in it. I want to select a value from the drop down. The ul class="ns-dropdown" and the option is many in that am trying to select and load Australian Dollar page.

Here is the Html tag:

<ul class="ns-dropdown">
<li class="ns-option><a class="c36 noUnderline">USD</a></li>
<li class="ns-option><a class="c36 noUnderline">AUD</a></li>
<li class="ns-option><a class="c36 noUnderline">NZD</a></li>
</ul>

Here is the code I tried

WebElement dropDownListBox = driver.findElement(By.className("ul.ns-dropdown")); 
Select clickThis = new Select(dropDownListBox);
clickThis.selectByValue("Australian Dollar");

But this not worked.

Please suggest me some ways to set the drop down value.

Thank You!

Balamurugan V
  • 9
  • 2
  • 10

2 Answers2

0

The Select class is meant to be used to be used with <select> tags rather than <ul> tags, so I imagine that you have been receiving an UnexpectedTagNameException when you try to instantiate clickThis?

For your scenario, you should first identify the parent <ul> tag using something like:

// Very similar to what you first tried!
WebElement dropDownListBox = driver.findElement(By.className("ns-dropdown"));`

As the child <li> tags you are trying to work with contain their own individual <a> tags, you can use the By.linkText() locator to find and click the currency option you require like so:

WebElement currency = dropDownListBox.findElement(By.linkText("Australian Dollar"));
currency.click();
Tom Trumper
  • 472
  • 2
  • 8
0

Select class is working only on <select> tags. In your case you need to open the dropdown to make the options visible and then click on the option you need

driver.findElement(By.className("ns-dropdown")).click(); // open the dropdown
driver.findElement(By.linkText("AUD")).click(); // choose Australian Dollar

If you have timing issues you can add explicit wait

WebDriverWait wait = new WebDriverWait(driver, 10);

driver.findElement(By.className("ns-dropdown")).click(); // open the dropdown
wait.until(ExpectedConditions.visibilityOfElementLocated(By.ilinkText("AUD"))).click(); // wait for the option to be visible before clicking on it.
Guy
  • 46,488
  • 10
  • 44
  • 88