【问题标题】:How can I wait for an element from another element in C# Selenium如何在 C# Selenium 中等待来自另一个元素的元素
【发布时间】:2018-05-01 04:36:29
【问题描述】:

有没有办法通过某种方式从另一个元素而不是整个驱动程序中搜索元素来执行wait.Until

示例:

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSec));

IWebElement element = wait.Until(ExpectedConditions.ElementExists(by));

我无法将'by' 修改得过于具体,并且当在驱动程序下搜索它并获取错误的元素时。

IWebElement element = wait.Until(drv => drv.FindElement(by));

此选项还在driver 下搜索。 我想要这样的东西:

public static IWebElement WaitElement(this IWebElement webElement, IWebDriver driver, By by, int timeoutInSec = 5)
    {
        try
        {
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSec));
                IWebElement element = wait.Until(webElement.FindElement(by));
        }

当我尝试编写此代码时,我收到此错误:

enter image description here

【问题讨论】:

  • 您所做的实际上是正确的。您可以从专利元素中找到子元素。
  • 我写的(最后一个代码)不“合法”,不被接受
  • 使用 By.CssSelector("#parentId #childId");
  • 达芙妮,你有没有找到解决办法?我遇到了同样的问题,我在循环找到的元素并且需要等待每个元素的子元素。

标签: c# selenium wait


【解决方案1】:

可能会迟到,但希望能帮助其他人。只需将第三个选项中最后一行的语法更改为以下内容:

IWebElement element = wait.Until(d => webElement.FindElement(by));

【讨论】:

    猜你喜欢
    • 2019-05-31
    • 1970-01-01
    • 2020-06-12
    • 1970-01-01
    • 2018-07-25
    • 2013-08-06
    • 2021-11-28
    • 2020-03-23
    • 1970-01-01
    相关资源
    最近更新 更多