我正在尝试使用Selenium WebDriver在Telerik RadComboBox Asp.Net控件中选择一个选项,但我无法使其始终如一地工作。我正在使用以下代码
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);
其中RadComboBoxArrow是Telerik RadComboBox中输入元素右侧的箭头。
我在多个地方使用此代码,并且仅在一个地方使用,有时会失败
System.TimeoutException: Timed out after 30 seconds --->
OpenQA.Selenium.NoSuchElementException: Unable to locate element:
{"method":"xpath","selector":"//input[contains(@id, 'rcbRadComboBox_Input')]"}
在建议使用SelectElement之前,请考虑以下事实:Telerik RadComboBox不会呈现选择标记。
我使用driver.Click()
首先,我单击组合以使其打开:
driver.Click(By.Id("ctl00_WCEContentPlaceHolder_RadToolbar_ReportsMenu_rttb1_ctl00_rcb_Reports");
然后我按ID单击元素。这恰好是列表中的第一个。
driver.Click(By.Id("ctl00_WCEContentPlaceHolder_RadToolbar_ReportsMenu_rttb1_ctl00_rcb_Reports_c1");