[英]how to select an option from the popup dropdown list using selenium webdriver c#
I have a telerik searchbox where I enter 'acc' and it automatically pops up the items starting with 'acc' and from that list I want to select 'Acabose'. 我有一个telerik搜索框,在其中输入“ acc”,它会自动弹出以“ acc”开头的项目,然后从该列表中选择“ Acabose”。
C# code: C#代码:
driver.FindElement(By.Id("ctl00_ctl14_tsfSearch_Input")).Click();
driver.FindElement(By.Id("ctl00_ctl14_tsfSearch_Input")).SendKeys("acc");
and HTML: 和HTML:
<div class="rsbSlide">
<div class="rsbPopup">
<ul class="rsbList">
<li class="rsbListItem">Acabose</li>
<li class="rsbListItem">Acabose 100mg</li>
</ul>
</div>
</div>
You could get all of the visible li items and iterate through them until you find the option with the text you want. 您可以获取所有可见的li项目并对其进行遍历,直到找到带有所需文本的选项。 (Note: I work with Selenium in Java, but the principle is the same in c#)
(注意:我在Java中使用Selenium,但是原理在c#中是相同的)
// code to enter the search goes here.
List<WebElement> rsbListItems = driver.findElements(By.className("rsbListItem");
for (int i = 0; i < rsbListItems.size(); i++) {
if (listItem.getText() == "Acabose 100mg") {
listItem.click();
}
}
Alternatively, if you know that Acabose is always (and forever) going to be the second item in the list, you can access it by index. 另外,如果您知道Acabose始终(永远)将成为列表中的第二项,则可以按索引访问它。
Try the below snippet 试试下面的代码片段
List<WebElement> telerikItemList = driver.findElements(By.className("rsbListItem");
for (WebElement telerikItemOpt: telerikItemList) {
if (telerikItemOpt.getText().equals("Acabose 100mg") {
telerikItemOpt.click();
break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.