Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent C# version of Java Webdriver @Findby?

I'm moving from a Java environment to .NET and need to write Webdriver tests using a page object model.

In Java I would use the following annotation:

@FindBy(linkText = "More details")
WebElement moreDetailsButton;

Please would someone be able to tell me how to define a WebElement using C#? Also, is the PageFactory.initElements used the same way?

Thanks Steve

like image 990
CynicalBiker Avatar asked Nov 04 '13 12:11

CynicalBiker


People also ask

What is the equivalent of class in C?

The closest thing you can get is a struct .

What is the equivalent temperature in C?

Celsius and Fahrenheit are two temperature scales. The Fahrenheit and Celsius scales have one point at which they intersect. They are equal at -40 °C and -40 °F.

What temperature in Fahrenheit is 50 C?

Answer: 50° Celsius is equal to 122° Fahrenheit.


1 Answers

Yes, there is a direct translation.

You are looking for FindsBy:

[FindsBy(How = How.LinkText, Using = "More details")]
private IWebElement moreDetailsButton;

As for the PageFactory.initElements, yes, it's a very similar thing in .NET, usually called in the constructor of the Page Object:

public class LoginPage
{
    private IWebDriver _driver;

    public LoginPage(IWebDriver driver)
    {
        _driver = driver;
        PageFactory.InitElements(_driver);
    }
}

Note, that the Selenium project is entirely open source. You can easily see the source the Page Objects 'helper' classes here.

like image 80
Arran Avatar answered Nov 05 '22 07:11

Arran