Struggling to extract the values from a KendoDropDown using Selenium

When using the selenium web driver, we are trying to retrieve a set of option values such as Last 30 days, Last 60 days, etc.

Attempts have been made to locate these elements using a CSS selector.

var timeperiodcss = "span.k-widget.k-dropdown.k-header select#selectDefaultTimePeriod option";

                var elements = element.FindElements(By.CssSelector(timeperiodcss));
                if (elements.Count >= 1)
                    break;

However, each time elements.count returns 0. We are unable to access these elements.

The HTML content for these cases is as follows:

<span class="k-widget k-dropdown k-header" style="width: 150px;" title="" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-owns="selectDefaultTimePeriod_listbox" aria-disabled="false" aria-readonly="false" aria-busy="false" aria-activedescendant="0936dfb5-4f8c-4dd4-826f-f802b6a719ff">
<span class="k-dropdown-wrap k-state-default" unselectable="on">
<select id="selectDefaultTimePeriod" style="width: 150px; display: none;" data-bind="kendoDropDownList:timePeriodOptions" data-role="dropdownlist">
<option value="">Select time period</option>
<option value="Last 30 days">Last 30 days</option>
<option value="Last 60 days">Last 60 days</option>
<option value="Last 90 days" selected="selected">Last 90 days</option>
<option value="Last month">Last month</option>
<option value="Last quarter">Last quarter</option>
<option value="Last 6 months">Last 6 months</option>
<option value="Last 12 months">Last 12 months</option>
<option value="Last 365 days">Last 365 days</option>
<option value="Full year 2016">Full year 2016</option>
</select>
</span>

If you know of any other method to retrieve these elements, please do let me know.

Answer №1

Do you have to manually choose each option from the dropdown menu? Or do you need to extract data from all options? Perhaps there's another requirement altogether?

Answer №2

Here's a helpful snippet in C#:

 SelectElement selectElement = new SelectElement(WebDriver.FindElement(By.CssSelector("span.k-widget.k-dropdown.k-header select#selectDefaultTimePeriod")));
            foreach (var option in selectElement.Options)
            {
                Console.WriteLine(option.GetAttribute("value"));
            }

Note: The provided CSS selector targets the main selector, not the individual options.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to make the first LI elements stand out in a nested structure by applying bold

I had an idea like this: #list li > a { font-weight: bold; } However, I only want the top level items to be made bold, not nested LI's within LI's -- hope that makes sense?? :) EDIT | <ul id="list"> <li><a href="#"& ...

The scroller's height is displayed at 100%

I'm experiencing an issue with the scrolling of a division. I've set the overflow to "scroll" for the division, but it's displaying at 100% height. Please refer to the screenshot provided. Can you advise me on which properties I should adjus ...

Looking for an Angular Material component that displays a list of attributes?

I am trying to create a dynamic list of properties in Angular using Material Design that adjusts for different screen sizes. For example, something similar to this design: https://i.stack.imgur.com/EUsmV.png If the screen size decreases, the labels shou ...

Dollar Sign vs "$$()" Sparkling Protractor with "by.css()" vs "$()"

I'm a bit confused about the purposes of the $ and $$ commands. I initially thought they were just substitutes for 'by.css', but why use $$? <element id = "eId"></element> Based on the example above, I assumed that these two l ...

How can I adjust the indentation in Angular Prime-ng's p-tree component?

In my project, I am utilizing the primg-ng tree component for the sidebar. Currently, the output is displayed as shown here: https://i.stack.imgur.com/kcSQt.png However, I am looking to maintain consistent indentation levels without any adaptive changes ...

Upgrade to a pop-up window interface add-on using Selenium in Python

https://i.stack.imgur.com/OxI25.png https://i.stack.imgur.com/h5a8k.png https://i.stack.imgur.com/jICQV.png https://i.stack.imgur.com/xnyq6.png Upon clicking the add-on icon, a new "pop-up" or "window" is created, essentially opening another HTML file ...

What is the best way to remove the box-model from an element?

Within my VueJS project, I am faced with nested elements that are generated dynamically like this: <container> <outerElement class="outer" v-for="obj in objects"> <innerElement class="inner" v-for="el ...

The combination of jQuery, using .load method in javascript to prevent scrolling up, making XMLHttpRequest requests, updating .innerHTML elements, and troubleshooting CSS/JS

While utilizing this code, CSS and Javascript are disabled (only HTML loads): function loadContent(limit) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (xhttp.readyState == 4 && xhttp.status ...

The navigation bar options are not collapsing as intended

When I resize my page to width:750px;, my navigation bar is not collapsing the items. Despite trying to edit my CSS, I am still clueless. Here is my live page. This is the CSS for my slidebar: @media (max-width: 480px) { /* Slidebar width on extra small ...

Error: The user prompt dialog was dismissed causing an UnhandledAlertException. The test runs successfully on the console but fails when executed in Jenkins

My test automation using selenium WebDriver runs smoothly in IntelliJ, on my computer's cmd, and even on the server's cmd (where Jenkins is running via a bat script). However, I encounter an exception when running the bat file with Jenkins. Here ...

Searching for an element in Python using Selenium can be done by using different methods such as finding

Having trouble retrieving the specific element below. I've attempted multiple methods including by class and CSS selector. <a href="http://www.google.ca" target="_blank" class="btn visit__link"> "Visit this Webpage" <br> "for more content ...

Text font automatically adjusts size in Chrome on Android

It seems that when a paragraph of text reaches a certain length, Google Chrome on Android decides to resize the text and make it larger (which can cause some interesting results). I've noticed that on my website, about half of the p-tags stick to the ...

Unable to include JUnit 5 Test Case

Currently, I am in the process of setting up a new project on my colleague's PC within Eclipse. This project involves the use of Selenium, JUnit 5.4, and Maven. However, we have encountered an issue where the option for New JUnit Juniper Test does not ...

fullpage.js: the content exceeds the height limit

I am currently working on customizing the jquery script fullpage.js for a website built on the French CMS "SPIP" (). This script is used to create a one-page website with both horizontal and vertical navigation. However, I have encountered an issue with ...

Clicking on a checkbox hidden beneath a hyperlink using Selenium WebDriver in C#

<div class="checkbox_tick fs-12 mb-14 js-agreement-wrapper"> <div class="input checkbox"> <input type="hidden" name="agreement" value="0"> <label for="agreement"> <input ...

Give a radio button some class

<input id="radio1" type="radio" name="rgroup" value="1" > <label for="radio1"><span><span></span></span>1</label> <input id="radio2" type="radio" name="rgroup" value="2" > <label for="radio2"><span ...

Ensure that a TestNG test is reliant on the successful completion of a previous test

I have a set of Selenium TestNG tests written in Java, where the success relies on an initial test that registers a user and completes a tutorial. Subsequent tests use the login credentials from this first test. Despite implementing retry logic (IRetryAna ...

Changing the value of a textarea in Angular forms using JavaScript

Having trouble with Angular forms? Try this: document.querySelector(TEXTAREA_SELECTOR).value = "some text" Methods like .title, .name, or .innerText don't seem to work. Consider trying these: document.querySelector(TEXTAREA_SELECTOR).dispa ...

Place the div's scrollbar at the beginning of its content

Recently, I put together a custom CSS modal that includes a scrollable div (without the modal itself being scrollable). Interestingly enough, when I initially open the modal, the scrollbar of the div starts at the top as anticipated. However, if I scroll d ...

combining HTML and CSS for perfect alignment

I'm having trouble trying to align an image and some text side by side. Below is the code that includes an image and text (Name and Age), but they are not aligning properly even after using float: left. Can anyone help me with this? Thank you. < ...