2

I am new to automation and currently exploring selenium Java for my application Trying to automate a web application with selenium Java.

I have looked online and can only find answers if the dropdown was 'Select'. Please suggest how i can select a value from the dropdown .

HTML code:

<span title="" class="k-widget k-dropdown k-header innova-invalid" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-owns="" aria-disabled="false" aria-busy="false" aria-activedescendant="32406016-a12b-4ce6-a9f7-56f84a0883bd" style="" xpath="1">
<span unselectable="on" class="k-dropdown-wrap k-state-default" style="">
<span unselectable="on" class="k-input"></span>
<span unselectable="on" class="k-select" aria-label="select"></span>
</span>
<select kendo-dropdownlist="$ctrl.dropdownList" k-data-source="$ctrl.dataSourceOptions.dataSource" k-data-text-field="'Display'" k-data-value-field="$ctrl.valueField" k-value-primitive="$ctrl.valuePrimitive" name="HSRisk" k-options="$ctrl.options" k-ng-model="$ctrl.model" k-rebind="$ctrl.rebindTimestamp" k-ng-disabled="$ctrl.isDisabled" ng-class="{'innova-invalid': $ctrl.hasError}" data-role="dropdownlist" style="display: none;" class="innova-invalid">
<option value="true"></option>
<option value="false"></option>
</select>
</span>
<span unselectable="on" class="k-dropdown-wrap k-state-default" style="">
<span unselectable="on" class="k-input"></span>
<span unselectable="on" class="k-select" aria-label="select">
<span class="k-icon k-i-arrow-60-down"></span>
</span>
</span>
<select kendo-dropdownlist="$ctrl.dropdownList" k-data-source="$ctrl.dataSourceOptions.dataSource" k-data-text-field="'Display'" k-data-value-field="$ctrl.valueField" k-value-primitive="$ctrl.valuePrimitive" name="HSRisk" k-options="$ctrl.options" k-ng-model="$ctrl.model" k-rebind="$ctrl.rebindTimestamp" k-ng-disabled="$ctrl.isDisabled" ng-class="{'innova-invalid': $ctrl.hasError}" data-role="dropdownlist" style="display: none;" class="innova-invalid">
<option value="true">
Yes
</option>
<option value="false">
No
</option>
</select>
</span>

2
  • Both of the dropdowns in your HTML are select elements -- what exactly are you trying to click here? Commented Oct 14, 2019 at 17:38
  • The <select> elements are hidden. Commented Oct 15, 2019 at 10:17

3 Answers 3

1

You can't click on options from select drop-downs. You need to handle them differently.

From your code sample I would say that in order to select an option you have to do this:

CODE SAMPLE

Select yourSelectSection = new Select(driver.findElement(By.id("YOUR_ID")));
yourSelectSection.selectByIndex(0); // by using index
yourSelectSection.selectByVisibleText("Yes"); // or by using text

Note: you have to import Select library. If you need to read more about this library you can do it here.

Sign up to request clarification or add additional context in comments.

Comments

0
Select yourSelectSection = new Select(driver.findElement(By.Xpath("dropdown-list")));
yourSelectSection.selectByIndex(0); // by using index
yourSelectSection.selectByVisibleText("true");

this will work

Comments

0

Please try the below code:

driver.findElement(By.id(“dropdownField”)).sendKeys(“mention text of required value from dropdown”); //send required option in dropdown field
driver.findElement(By.id(“option1”)).click(); 

Or try with the below code:

List<WebElement> options = driver.findElements(By.xpath(“”));
for(WebElement option : options) {
if (option.getText().contains(“mention text of required value from dropdown”)) {
option.click();
break;
}

Please refer to the link for more details- how to select a particular value in a dropdown without using the methods of Select class in Selenium.

Comments

Your Answer

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.