1

Here is code I'm using to scroll through a list of districts:

IWebElement districtsList = modelAddInvoice.ReturnDistrictInvoiceAddDistrict();
districtsList.Click();
districtsList.SendKeys(Keys.ArrowDown);
Thread.Sleep(1000);
districtsList.SendKeys(Keys.ArrowDown);
Thread.Sleep(1000);
districtsList.SendKeys(Keys.ArrowDown);
Thread.Sleep(1000);
districtsList.SendKeys(Keys.ArrowDown);
Thread.Sleep(1000);
districtsList.SendKeys(Keys.ArrowDown);
Thread.Sleep(1000);
districtsList.SendKeys(Keys.ArrowUp);
Thread.Sleep(1000);
districtsList.SendKeys(Keys.ArrowUp);
Thread.Sleep(1000);
districtsList.SendKeys(Keys.ArrowUp);
Thread.Sleep(1000);
districtsList.SendKeys(Keys.ArrowUp);
Thread.Sleep(1000);
districtsList.SendKeys(Keys.ArrowUp);

This will do what's expected. I scroll to the 5th item, then back to the first.

If I try this, nothing happens:

IWebElement districtsList = modelAddInvoice.ReturnDistrictInvoiceAddDistrict();
Actions selectDistrict = new(_browserFixture.EdgeDriver);
selectDistrict.MoveToElement(districtsList).Click();
// or
selectDistrict.MoveToElement(districtsList).Perform();

End users will be using their mouse. So, using space bar or click to expose the list and then scrolling with Send Keys, that's not real-world. Nothing happens at all when using Actions.

If I'm not using Kendo items, the Actions class methods do work.

Googling for this specific use case hasn't exposed yet this same scenario.

Could not copy the HTML but here is a screen shot showing District 5 selected.

enter image description here

So, there's a bit of CSS magic happening, this is not the usual Drop- Down List.

Making a mouse hover, mouse click, scroll, etc. just may not work for this use case.

Thanks for helping.

marc_s
760k186 gold badges1.4k silver badges1.5k bronze badges
asked Dec 10, 2025 at 19:07
1
  • You need to edit your question and add the portion of the HTML containing the label and dropdown, "District: * [ 5 v ]". You should be able to at least copy/paste that portion of the page. You also need to add the locator(s) you are using to the question. Right now you're calling a method that you haven't provided the code for. Commented Dec 11, 2025 at 5:54

1 Answer 1

3

Since we don't have the HTML of your page, I found a sample Kendo UI dropdown demo page and wrote a script against it. I had to create a custom method to set the dropdown value because the first click never registers correctly. The first click opens and then immediately closes the dropdown... so I have to click again and wait until the desired element is visible.

The main script

IWebDriver driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Url = "https://demos.telerik.com/kendo-ui/dropdownlist/index";
SetCity(driver, "Berlin");
driver.Quit();

The SetCity() method

public void SetCity(IWebDriver driver, string city)
{
 WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
 IWebElement dropdown = wait.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("span.k-input-value-text")));
 dropdown.Click();
 while (true)
 {
 try
 {
 wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//span[text()='Berlin']"))).Click();
 break;
 }
 catch (Exception e) when (e is WebDriverTimeoutException || e is ElementNotInteractableException)
 {
 dropdown.Click();
 }
 }
}
answered Dec 11, 2025 at 6:25
Sign up to request clarification or add additional context in comments.

9 Comments

You'll have to update the locators to work with your page but this should at least get you started.
Thanks, Jeff. So sorry I could only upvote it once :)
Jeff, Sometimes the selected district is one less than the one expected. I've set the district to 8. When Run until Failure is selected, after 6 to 8 iterations one will fail. The selected value will be 7, even though 8 was specified. So it's a timing issue. Any ideas?
I would strongly suggest you don't use ArrowUp/ArrowDown. I think it's the likely cause of what you are describing. Instead select the elements by contained text as I am here. My code will retry until it succeeds, which should fix the issue you are describing.
Not doing the arrow up, down. Using just the code as I set it up as above. I'm thinking a timing issue? Will have to look it over more.
Found what was up. My original code still had a line in it that created and clicked the drop down prior to calling the code in your solution. Just spotted that now. Commenting out those lines and using Run Until Failure again is finding other unrelated issues now, so I'm on the right track.
This might be a 'scroll into view' scenario. Only the first 5 districts out of 12 are in immediate view. Could be 6 or higher, when we want these, we need to scroll that element in to view.
I realize edits need to be verified. However, edits I put in yesterday showing how the suggested fix was implemented evidently got purged. This is great: Thanks for submitting an edit. It is only visible to you until it’s been approved by trusted community members. But PLEASE be less judgmental -- I'm just showing how I implemented the suggestion in case it's incorrect. I'm not pirating the answer.
I understand your intent but that's now how StackOverflow works. The some of the edits you made were only useful to you. It contained code that only you would understand and also referenced code that only you had access to, making this answer less useful for the larger crowd. My answer doesn't have to match exactly what you used... as long as the code was helpful, which I'm assuming it was, that's the goal. Thanks.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.