【问题标题】:Explicit wait Selenium Webdriver for element in hand显式等待 Selenium Webdriver 获取现有元素
【发布时间】:2016-10-11 10:26:04
【问题描述】:

我在 C# 上使用 selenium webdriver,并且我正在使用页面对象模块。现在我需要一个用于显式等待的语法,因为我已经拥有了 web 元素。

[FindsBy(How = How.Id, Using = "Passwd")]
public IWebElement Password {get;set;}

[FindsBy(How = How.Id, Using = "signIn")]
public IWebElement Signin { get; set; }

我需要等到找到元素密码。

在使用这个模块之前,我正在使用:

WebDriverWait wait = new WebDriverWait(driver.driver, TimeSpan.FromSeconds(Time));
wait.Until(ExpectedConditions.ElementExists(by));

现在我需要使用手中的元素。

【问题讨论】:

    标签: c# selenium


    【解决方案1】:

    您应该尝试使用ExpectedConditions.ElementToBeClickable,它将接受IWebElement 以及输入,并等待元素可见并启用如下:-

    WebDriverWait wait = new WebDriverWait(driver.driver, TimeSpan.FromSeconds(Time));
    wait.Until(ExpectedConditions.ElementToBeClickable(Password));
    

    【讨论】:

    • ElementToBeClickable 在预期条件下不被接受。它给出了............“OpenQA.Selenium.Support.UI.ExpectedConditions”不包含“ElementToBeClickable”的定义
    • 你可以看到这个 c# 文档的链接,seleniumhq.github.io/selenium/docs/api/dotnet/html/… 它由ExpectedConditions 支持。我很奇怪你为什么会出错
    • 你用的是什么版本的硒??
    • Selenium Webdriver 2.44.0
    • 这就是你遇到麻烦的原因,你应该将你的 selenium 版本升级到 2.48.1.0 或更高版本,因为它支持 2.48.1.0 版本。它在提供的链接文档中清楚地提到了谢谢
    【解决方案2】:

    请检查是否有帮助

    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
    
    wait.Until(driver => Password.Displayed);
    

    【讨论】:

      【解决方案3】:

      添加显式等待并等待Password.Displayed 为真:

      [FindsBy(How = How.Id, Using = "Passwd")]
      public IWebElement Password {get;set;}
      
      [FindsBy(How = How.Id, Using = "signIn")]
      public IWebElement Signin { get; set; }
      
      WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
      wait.Until(Password.Displayed);
      

      完全披露,我在这里找到了答案:https://groups.google.com/forum/#!topic/webdriver/xdFsocNMSNc

      【讨论】:

        【解决方案4】:

        预期条件方法以By 作为参数,而您想使用ElementIsVisible,即以下应该可以工作:

        WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
        wait.Until(ExpectedConditions.ElementIsVisible(By.Id("Passwd")));
        

        【讨论】:

          猜你喜欢
          • 2013-12-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-05-28
          • 1970-01-01
          • 2012-03-26
          • 2016-12-25
          • 1970-01-01
          相关资源
          最近更新 更多