如何将Wait.Until与Selenium C#一起用于现有元素 [英] How to use Wait.Until with Selenium C# for existing element

查看:508
本文介绍了如何将Wait.Until与Selenium C#一起用于现有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在selenium(C#)中使用wait.until的方法,但要用于现有元素.这样:

I looking for a way to use the wait.until in selenium(C#) , but for existing element. That way:

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

现在,我想对上面的元素使用wait.until. 有什么办法可以做到吗? 谢谢 亚尼夫

now , I would like to use the wait.until for the element above. 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")));
    }
}

在子页面中的元素初始化之前,将从父构造函数调用方法WaitUntilExist().由于它是抽象的,因此将继承子类中的方法.

The method WaitUntilExist() will be called from the parent constructor before the elements initialization in the child page. Since it's abstract the method in the child class will be excuted.

这篇关于如何将Wait.Until与Selenium C#一起用于现有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆