IMLiviu
IMLiviu

Reputation: 1016

How to select an option from the Telerik RadComboBox using Selenium WebDriver and c#?

I am trying to select an option in a Telerik RadComboBox Asp.Net control using Selenium WebDriver and I can't make it work consistently. I am using the following code

var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
  wait.Until(ExpectedConditions.ElementIsVisible(RadComboBoxArrowBy));

RadComboBoxArrow.Click();
var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//input[contains(@id, 'rcbRadComboBox_Input')]")));
RadComboBox.SendKeys(division);
RadComboBox.SendKeys(Keys.Tab);

where RadComboBoxArrow is the arrow at the right of the input element in the Telerik RadComboBox.

I am using this code in multiple places and only in one it fails from time to time with

System.TimeoutException: Timed out after 30 seconds --->
OpenQA.Selenium.NoSuchElementException: Unable to locate element: 
{"method":"xpath","selector":"//input[contains(@id, 'rcbRadComboBox_Input')]"}

Before suggesting the use of SelectElement please consider the fact that Telerik RadComboBox doesn't render a select tag.

Upvotes: 4

Views: 1683

Answers (1)

Scott Loveland
Scott Loveland

Reputation: 31

I use driver.Click()

First I click the combo to cause it to open:

driver.Click(By.Id("ctl00_WCEContentPlaceHolder_RadToolbar_ReportsMenu_rttb1_ctl00_rcb_Reports");

Then I click the element by ID. This one happens to be the first in the list.

driver.Click(By.Id("ctl00_WCEContentPlaceHolder_RadToolbar_ReportsMenu_rttb1_ctl00_rcb_Reports_c1");

Upvotes: 1

Related Questions