简体   繁体   English

C# Selenium:等到下拉加载/显示值?

[英]C# Selenium: Wait until dropdown loads/shows value?

I have a program in VS using C# with Selenium that inputs data into a dropdown textbox.我在 VS 中有一个使用 C# 和 Selenium 的程序,它将数据输入到下拉文本框中。

But the program gets an error because it takes a long time to show the value before it clicks Enter.但是程序出现错误,因为在单击 Enter 之前需要很长时间才能显示该值。

I'm also using ElementExists, ElementVisible, ElementClickable methods.我也在使用 ElementExists、ElementVisible、ElementClickable 方法。

Is there a way to wait until the dropdown shows the value before it clicks Enter?有没有办法等到下拉菜单显示值后再点击回车? (Is there a way to wait until the dropdown loads?) (有没有办法等到下拉加载?)

I also increased the duration of Thread.Sleep but it's too inconsistent.我还增加了 Thread.Sleep 的持续时间,但它太不一致了。

Appreciate if you could help me out.如果你能帮助我,不胜感激。 Thanks in advance.提前致谢。

var dropDown= wDriver.FindElements(By.XPath("//input[contains(@aria, 'false')and not(@class)]"));

dropDown.SendKeys(value);

Thread.Sleep(2000);

dropDown.SendKeys(Keys.Enter);

NOTE: (I'm not using SelectElement because the dropdown element can only be access thru Xpath.)注意:(我没有使用 SelectElement 因为下拉元素只能通过 Xpath 访问。)

have you checked for waitForElementPresent command.您是否检查过 waitForElementPresent 命令。

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[contains(@aria, 'false')and not(@class)]")));

or you can use wait untill expected condition.或者您可以使用等到预期条件。

wait.until(
    ExpectedConditions.presenceOfNestedElementsLocatedBy(By.xpath(<"//input[contains(@aria, 'false')and not(@class)]">), By.tagName("input"))
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM