如何等待直到下拉选择的选项使用硒更改? [英] How to wait until dropdown selected option changes using selenium?
本文介绍了如何等待直到下拉选择的选项使用硒更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有时,基于页面上的其他操作,下拉菜单中选择的项目会自动更改,而无需重新加载页面(此下拉菜单每次都具有相同数量的选项). 我们如何才能等到使用Selenium Webdriver C#下拉选择的项目进行更改?
Sometimes, based on some other actions on page, a dropdown selected item changes automatically without page reload (this dropdown has same no. of options everytime). How can we wait until dropdown selected item changes using selenium webdriver C#?
<select name="ddlFruit_N" id="ddlFruit_N" class="Searchddl" style="text-decoration: none; width: 152px; height: 22px;">
<option value="">Select</option>
<option value="447">Grapes</option>
<option value="448">Mango</option>
<option selected="selected" value="449">Apple</option>
</select>
推荐答案
请尝试下面的代码来等待下拉选项的更改.
Please try below code to wait for changed dropdown option.
public static SelectElement FindSelectElementWhenPopulated(IWebDriver driver, By by, int delayInSeconds, string optionText)
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(delayInSeconds));
return wait.Until<SelectElement>(drv =>
{
SelectElement element = new SelectElement(drv.FindElement(by));
if (element.SelectedOption.ToString().Contains(optionText))
{
return element;
}
return null;
}
);
}
我这样称呼它,以等待更改的下拉选项橙色"
and I call it like this to wait for changed drop down option "Orange"
Myclass.FindSelectElementWhenPopulated(driver, By.CssSelector("#ddlFruit_N"), 20, "Orange");
这篇关于如何等待直到下拉选择的选项使用硒更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文