0

I've this html body for a kendo dropdown list which has only one attribute i.e. id which is dynamically changing, how do i identify this object on every page refresh accurately. other attributes like class and tab index already are present with same values multiple times on the same page for other dropdowns-

<span role="listbox" unselectable="on" class="k-dropdown-wrap k-state-default" id="dde13a91-2bf3-4e41-af72-bee1b881a8d9" dir="ltr" readonly="false" tabindex="0" aria-disabled="false" aria-readonly="false" aria-haspopup="true" aria-expanded="false" aria-owns="48f666d8-4c3c-43a8-a4dc-8e7a9961a0ef" aria-activedescendant="ca3c4431-3ebf-46c0-9510-a64a32eae108-C.US.0000110896">
            <span unselectable="on" class="k-input">
               <!---->
               <!---->2018 ALBERTSONS / Beverage Mixes
           </span>
           <span unselectable="on" class="k-select">
               <span class="k-i-arrow-s k-icon"></span>
           </span>
           <!---->
        </span>
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • You can use List store your all elements into the list by using XPath – Dhru 'soni Oct 04 '18 at 08:42
  • @chinmayraskar Which _Selenium Language Binding Art_ are you using? _Java_ / _Python_ / _C#_ / _NodeJS_ ? – DebanjanB Oct 04 '18 at 09:47
  • 1
    If you can explain in English how you would look at an HTML page and identify the element that you want to retrieve, then we can help you translate that English description into XPath. If you can't tell us what criteria you use to recognize the right element, then we can't help you. – Michael Kay Oct 04 '18 at 10:57

3 Answers3

1

If there is a always present value in dropdown, You can try to find this value by text or something, and then get a parent: XPath: Get parent node from child node

Other way is to get it by xpath of structure, like: div[3]/.../span etc. It is not good as every change can fail Your test, but if You have no other options, then You might want to try this.

Deryl
  • 64
  • 5
  • Thanks for you solution, but the values in the dropdown are hidden and are visible only when user selects a particular value on runtime. So there's no possibility of tracing it from the child node or any relative reference. – chinmay raskar Oct 05 '18 at 06:19
1

To click on the element with the only attribute-text as 2018 ALBERTSONS / Beverage Mixes you need to induce WebDriverWait for the element to be clickable and you can use the following solution:

  • (Java) xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='k-dropdown-wrap k-state-default' and @role='listbox']//span[@class='k-input']"))).click();
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
0

I found a workaround to locate the element:

First get the xpath of the span tag inside the dropdown using it's text as below: //text()[contains(.,'2018 ')] since '2018 ' is common irrespective of adjacent text

Then move up to the parent tag of the dropdown to locate the dropdown frame which can be collapsed on click: //text()[contains(.,'2018 ')]/parent::/parent::

then simply click on the element which is located. driver.findElement(By.xpath("//text()[contains(.,'2018 ')]/parent::/parent::")).click();