0

I need to select a category from the below html. I tried different options, and different ways showed in the blogs, but not able to select the options. Any help will be appreciated.

One way I am using as (Not a better one)

private boolean select_dropdown_xpath(String value, String seleniumObjectValue) {
 try {
 boolean isListItemFound = false;
 int i = 0;
 do {
 i++;
 String category = driver.findElement(By.xpath(seleniumObjectValue+"/div["+ i +"]")).getText();
 if(category.equals(value)) {
 driver.findElement(By.xpath(seleniumObjectValue+"/div["+ i +"]")).click();
 isListItemFound = true;
 }
 } while (isListItemFound == false);
 if(!(isListItemFound)) {
 return false;
 } 
 } catch(Exception e) {
 return false;
 }
 return true;
}

Tool: Selenium WebDriver 2.28 with Java

Thanks Purna

HTML:

<div class="drop-down">
 <div class="label_field">
 <label>Category:</label>
 <fieldset>
 <div id="Ccategory" class="jSym_select_element jSym_pie jSym_noSelectText false hover" tabindex="0" textval="Default" style="width: 350px;">
 <div class="jSym_drop_arrow false"/>
 <div class="jSym_select_inner false">Default</div>
 </div>
 <div id="selectDrop" class="jSym_select_drop jSym_noSelectText " style="height: 50px; width: 350px; margin-top: 10px;">
 <div class="jSym_select_item jSym_noSelectText" optionval="Default">Default</div>
 <div class="jSym_select_item jSym_noSelectText" optionval="Reset">Reset</div>
 </div>
 <select id="select_category" class="jSym_dropdown" name="category" style="visibility: hidden;">
 <option value="Default">Default</option>
 <option value="Reset">Reset</option>
 </select>
 </fieldset>
 </div>
</div>
Ripon Al Wasim
37.9k42 gold badges159 silver badges179 bronze badges
asked Feb 1, 2013 at 11:11

1 Answer 1

5

Try this code:

Select sele = new Select(driver.findElement(By.id("select_category")));
//Select the dropdown by using the displayed value.
sele.selectByVisibleText(`displayed value`);
//or you can Select the dropdown by using the index value.
sele.selectByIndex(`index value`);
 //or you can Select the dropdown by using the value attribute.
sele.selectByIndex(`value in the value attribute`);

In your case the dropdown visibility is hidden. So, first make it as visible by using JavaScript Executor class. Then use the above code.

answered Feb 1, 2013 at 11:38

1 Comment

How to make the drop-down visible by using JavascriptExecutor in Selenium?

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.