-1

Here is my selenium code:

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//ul[id()='ddlSaleItem_listbox]")));
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//ul[id()='ddlSaleItem_listbox']"))).click();

here is my HTML code:

<div unselectable="on" style="overflow: auto; position: relative; height: auto;">
   <ul unselectable="on" class="k-list k-reset" tabindex="-1" aria-hidden="true" id="ddlSaleItem_listbox" aria-live="polite" data-role="staticlist" role="listbox">
  <li tabindex="-1" role="option" unselectable="on" class="k-item k-state-focused" aria-selected="true" data-offset-index="0" id="91877f7d-e75f-4218-8f6f-e87aaafe5e27">Health Club  Facility  Quarterly</li>
  <li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="1">Hrealth Club  Half Yearly</li>
   </ul>
</div>

please help me to get this done

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
MurugesanK
  • 21
  • 6

3 Answers3

1

The xpath you used is not valid, it should be @id instead of id()

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//ul[@id='ddlSaleItem_listbox']"))).click();
// or using By.id instead of xpath
wait.until(ExpectedConditions.elementToBeClickable(By.id("ddlSaleItem_listbox']"))).click();

No need to use ExpectedConditions.visibilityOfElementLocated, elementToBeClickable is doing it already.

Guy
  • 46,488
  • 10
  • 44
  • 88
1

Seems, you are using wrong xpath it should be //ul[@id='ddlSaleItem_listbox].

And i would suggest if id is available for element then better to go with it.

wait.until(ExpectedConditions.elementToBeClickable(By.id("ddlSaleItem_listbox"))).click();

While handling kendo dropdown you might face problem like element not getting click and there is no error or other element getting click instead of expected one. In such case you can use JavascriptExecutor to perform click on intended element.

e.g.

WebElement element = driver.findElement(By.id("ddlSaleItem_listbox"));
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);
NarendraR
  • 7,577
  • 10
  • 44
  • 82
1

To click the kendo dropdown using Selenium you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("ul.k-list.k-reset#ddlSaleItem_listbox"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//ul[@class='k-list k-reset' and @id='ddlSaleItem_listbox']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352