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

Creating a scoreboard layout with HTML and CSS

I am attempting to create a scoreboard in the following format: 0 - 0 Home - Away The issue I am facing is that if the length of the Home team's name is longer, it pushes the dash (-) further. I want the dash to be a ...

Basic parallax application, failing to achieve the desired impact

My goal is to create a scrolling effect where the header text moves down slightly, adding some margin on top to keep it in view. I found the perfect example of what I want to achieve with the header text at this website: After spending hours working on i ...

selenium.common.exceptions.ElementNotInteractableException: Alert - The element cannot be interacted with at this time when attempting to interact with an element using Selenium

Looking for assistance with the following code snippet: Trying to locate the cl_login tag within a parent div wrapper class in the DOM: c24-uli-input-wrapper c24-uli-input-wrapper-email c24-uli-input-info style-scope unified-login Using an xpath locator, ...

Collaboration of Bootstrap components

I am facing an issue with two divs that are supposed to be displayed side by side in a normal browser. However, when the browser window is resized, the first div loses its height and the second div overlaps into it. I attempted to set the body's min h ...

Is there a way to show textboxes stacked on top of each other without causing them to

Here is the HTML snippet I am working with: <div> <p><label>Faculty <input type="text" class = "f"></label></p> <p><label >Department<input type="text" class = "f"></label></p> ...

Experiencing a problem with uploading an image for the profile picture using Selenium

Having trouble uploading the image. When clicking on the "add photo" button, a browser popup appears but it is not selecting the file path or clicking the open button. WebElement uploadElement=ep.Addphoto(); uploadElement.click(); uploadElement.sendKeys(" ...

Pyinstaller encounters an error when attempting to run a script that utilizes the Selenium webdriver

I'm having trouble running my .exe file when using Selenium - webdriver in my code. Below is the script I've created named test.py: from selenium import webdriver driver = webdriver.Firefox() url = "https://google.com/" driver.get(url) After ...

Tips for addressing flickering issues when scrolling on your device

I am facing an issue with two elements that are set to a fixed position on the page. When these elements reach the bottom of the page, I want them to revert back to a static position using JavaScript. The problem occurs when trying to scroll by clicking a ...

Tips for applying horizontal padding to the container-fluid class in Bootstrap 5

I'm struggling with the CSS code I wrote: .container-fluid{padding 3% 15%;} It's only adjusting the vertical padding to 3%, and there's no change in horizontal padding. #title { background-color: #ff4c68; } .container-fluid { pad ...

Using a percentage width on a <div> element with the "overflow-x: scroll" property does not seem to be functioning properly, even when encapsulated within

My code includes a div within another div, taking up 50% of the page's width: <div id="mainContainer" class="mainContainer"> <div id="scroller" class="scrolling"> <!-- items here should make the div really long --> & ...

What is the best way to compile an array of permissible values for a specific CSS property?

One interesting aspect of the CSS cursor property is its array of allowed values, ranging from url to grabbing. My goal is to compile all these values (excluding url) into an array in JavaScript. The real question is: how do I achieve this without hardco ...

The textbox element was not found, as per org.openqa.selenium.NoSuchElementException

I've been scouring the depths of online forums for a solution to my "org.openqa.selenium.NoSuchElementException: Unable to locate element" issue, but none seem to quite match up with my case. As a novice in the world of coding and selenium, any assist ...

Issue with the appearance of the footer in my Wordpress template

After creating a WordPress template, I noticed that the footer is not extending to 100% width as expected. Check out the page here Any suggestions on why this might be happening? Could it be due to a missing closing div tag somewhere in the code? Thank ...

Error logging out of Yahoo Mail using Selenium WebDriver

I am a beginner with Selenium WebDriver and I am currently working on a script to log into a yahoo email account and then log out. I have successfully implemented the login functionality, however, I am facing issues with the sign out part. The error messag ...

What could be causing the bootstrap columns to automatically shift onto separate lines?

Check out my code snippet: html, body { width: 100%; height: 100%; margin: 0; padding: 0; overflow-x: hidden; } .row { width: 100%; height: 80%; margin: 0px; padding: 0px; } body { background: #EFEFEF; } .container-fluid { wid ...

The placement of the floating element completely messes up the

Whenever I try to float an element in my magnificent popup, the layout gets all messed up. You can see for yourself by trying to put the image and text next to each other using "float: left": http://jsfiddle.net/a7Vj8/1/ Every time I attempt to float th ...

Scrollbar Overlay

I am currently working on an HTML page where I have implemented a CSS style overlay lightbox effect using CSS and jQuery. If you want to take a look at the code, click here One issue I am facing is that when I resize the window height so the right-hand s ...

Relocate the preview division below the button in the Kartik File Input Widget

There are two input file buttons that allow users to upload an image on each button. Upon selecting an image, a preview of the image will be displayed above the button. The current layout is shown here: When images of different sizes are uploaded, the but ...

Avoid having individual words centered on a single line of text

Currently, I'm in the process of developing a website using WooCommerce, WordPress, and Elementor. I've encountered an issue where only one word appears on each line and have tried various solutions such as hyphens, word-break, and line-break wit ...

Bootstrap requires Visual Studio Code live-server plugin to function properly

I have been utilizing the Visual Studio Code IDE for my coding projects, along with a helpful plugin called "live server" that allows for quick checks of code changes. Everything was running smoothly with Bootstrap until I encountered an issue. When I att ...