How to select a value from Kendo UI MVVM drop down in automated test?

564 views Asked by At

Could anyone please help me with selecting a value from Kendo UI MVVM drop down using Selenium Java?

<input class="k-input fieldFullWidth" autocomplete="off" style="width: 100%;" title="" role="combobox" aria-expanded="false" tabindex="0" aria-disabled="false" aria-autocomplete="both" aria-owns="ddStore_listbox" type="text">

<input id="ddStore" class="fieldFullWidth" data-role="combobox" style="display: none;" aria-disabled="false" data-bind="value: selectedAsset.StoreID, comboboxText: selectedAsset.StoreName">

I tried to use JavascriptExecutor. But, it gives me org.openqa.selenium.WebDriverException: unknown error: Cannot set property 'value' of null error.

jse.executeScript("document.getElementById('ddstore').value = '1';");

Thanks

2

There are 2 answers

4
NarendraR On

Use ExplicitWait to wait until visibility of <input>tag element and then send your dropdown value as input

WebDriverWait wait = new WebDriverWait(driver, 120);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ddStore")));

driver.findElement(By.id("ddStore")).sendKeys("dropDown_Value"); // send your dropdown value as input

`

The another alternative way is to use JavascriptExecuter as your tag contains attribute style="display: none;" so might be changes of invisibility of element

 JavascriptExecutor jse = (JavascriptExecutor)driver;
 jse.executeScript("arguments[0].value='your_dropdown_value';",driver.findElement(By.id("ddStore")));
0
Maninder On

You can try the following code to select dropdown value:

Select mydrpdwn = new Select(driver.findElement(By.id("ddStore"))); //id of dropdown  
mydrpdwn.selectByVisibleText("name");// Value you wanted to select