简体   繁体   English

如何将Wait.Until与Selenium C#一起用于现有元素

[英]How to use Wait.Until with Selenium C# for existing element

I looking for a way to use the wait.until in selenium(C#) , but for existing element. 我正在寻找一种在selenium(C#)中使用wait.until的方法,但要用于现有元素。 That way: 那样:

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

now , I would like to use the wait.until for the element above. 现在,我想对上面的元素使用wait.until。 any way I can do that? 有什么办法可以做到吗? Thanks Yaniv 谢谢亚尼夫

You can create an abstract page object as parent to your page object and call an abstract method, which is implemented in the children pages, from the constructor: 您可以创建一个抽象页面对象作为该页面对象的父对象,并从构造函数中调用一个在子页面中实现的抽象方法:

public abstract class AbstractPage
{
    protected AbstractPage()
    {
        WaitUntilExist();
    }

    protected abstract void WaitUntilExist();
}

public class MyPage : AbstractPage
{
    [FindsBy(How = How.Id, Using = "SomeID")]
    private IWebElement SearchButton;

    public MyPage()
    {
    }

    protected override void WaitUntilExist()
    {
        wait.Until(ExpectedConditions.ElementExists(By.Id("SomeID")));
    }
}

The method WaitUntilExist() will be called from the parent constructor before the elements initialization in the child page. 在子页面中的元素初始化之前,将从父构造函数中调用方法WaitUntilExist() Since it's abstract the method in the child class will be excuted. 由于它是抽象的,因此将继承子类中的方法。

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

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