0
votes

I am trying to locate a dropdown list and select an option from it, however I'm unable to locate the dropdown due to there is no, id, name, or any obvious other locators to access that.

I have even tried using xpath , they only success I had was to click on that dropdown and open the list however I was not able to select any item from it.

I even tried something like: String metric = "html/body/div[3]/div[2]/form/div/table/tbody/tr1/td[2]/div/a"; click(driver.findElement(By.xpath(metric))); select("Connection Status").from(By.cssSelector("select2-choice")); the following is the screen shot of options I need to select:

enter image description here

please help me out with that..

I have provided the JS code below

<form> <div class="my-form"> <span class="table-title">Widget Information</span>  
<table> <tbody> <tr class="ui-field"> <td align="right" width="30%">Metric Type</td>
<td> <div id="s2id_autogen1" class="select2-container" style="display: inline;"> <a
class="select2-choice" tabindex="-1" onclick="return false;" 
href="javascript:void(0)"> <span class="select2-chosen">Connection Status</span> <abbr
class="select2-search-choice-close"></abbr> <span class="select2-arrow"> <b></b>
</span> </a> <input id="s2id_autogen2" class="select2-focusser select2-offscreen" 
type="text">
1

1 Answers

0
votes

First, do a WebElement click on the menu to expand it. Then, do something like this:

List<WebElement> menuItems = driver.findElements( 
    By.xpath( ".//div[@class='select2-container']/*/option" ) );
for ( WebElement el: menuItems ) {
    if ( el.getText().equals("Item I am looking for") ) el.click();
    break;
}

Or something along those lines should work.