1
<div class="k-list-scroller" unselectable="on" style="height: 200px;">
<ul id="Salutation_listbox" class="k-list k-reset" unselectable="on" tabindex="-1" aria-hidden="false" aria-live="off" data-role="staticlist" role="listbox">
<li id="c77e68b5-ded1-48a8-932c-74a5b2f45c66" class="k-item k-state-selected k-state-focused" data-offset-index="0" unselectable="on" role="option" tabindex="-1">Salutation</li>
<li class="k-item" data-offset-index="1" unselectable="on" role="option" tabindex="-1" style="">Mr</li>
<li class="k-item" data-offset-index="2" unselectable="on" role="option" tabindex="-1">Mrs</li>
<li class="k-item" data-offset-index="3" unselectable="on" role="option" tabindex="-1">Miss</li>
<li class="k-item" data-offset-index="4" unselectable="on" role="option" tabindex="-1">Ms</li>
<li class="k-item" data-offset-index="5" unselectable="on" role="option" tabindex="-1">Dr</li>
<li class="k-item" data-offset-index="6" unselectable="on" role="option" tabindex="-1">Prof</li>
<li class="k-item" data-offset-index="7" unselectable="on" role="option" tabindex="-1">Rev</li>
</ul>
</div>
</div>

This is a salutation drop down, I need to select the Mr from the drop down values. My code is incomplete I don't know how to write a script for it, but my code is as follows,

driver.findElement(By.className("k-input")).click();
Thread.sleep(1000);
driver.findElement(By.className("k-item")).click();
driver.findElement(By.tagName("Mr")).click();

2 Answers 2

2

As it is a KendoUI DropDown

You have to first click on the dropdown element.Could be span or div

I have taken the Demo Site to demsonstrate how you can select the values

I'm going to select Orange value from Cap Color DropDown

enter image description here

As you can see the element is span with class k-widget k-dropdown k-header.

You have to click on that first. Then only you'll get the ul list populated.

From that you can select any k-item by using the simple xpath.

//ul[@id='idOfUl']/li[@class='k-item' and text()='itemName']

For you it should be

//ul[@id='Salutation_listbox']/li[@class='k-item' and text()='Mr']

Sample Code

public void testKendo() {
        driver.get("http://demos.telerik.com/kendo-ui/dropdownlist/index");

        String capColorDropDown = "//span[@role='listbox']";

        driver.findElement(By.xpath(capColorDropDown)).click();

        String itemName = "Orange";

        String listId = "color_listbox";

        String xpathForItem = "//ul[@id='" + listId + "']/li[@class='k-item' and text()='" + itemName + "']";

        driver.findElement(By.xpath(xpathForItem)).click();

        driver.quit();
    }
Sign up to request clarification or add additional context in comments.

1 Comment

@user3836485 Then you can accept it as answer
0

I understand that you requirement is accessing the element through classname. so i have modified it as xpath with attributes as class and text contained in it.

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getelementsbyclassname('k-list-scroller').setAttribute('unselectable', 'off')");
js.executeScript("document.getelementsbyclassname('k-list k-reset').setAttribute('unselectable', 'off')");
driver.findElement(By.xpath("//li[text()='Mr'and class='k-item']")).click();

2 Comments

While executing this comment i am getting the error message as, unknown error:document.getelementsbyclassname is not a function
It should be getElementsByClassName

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.