I am creating an automation test framework for Selenium test using Page Object Model and Pagefactory.

The website I am testing can create new pages that a person can write content to which is then displayed on the website. The specific testcase I am trying to achieve is a simple one: create a new page - delete the new page.

My testcase:

public void CanDeleteTextPage()
    Pages.Navigation.Login("user1", "password1");

To make this work I use an implicit wait when initializing the test project


However, due to the speed of Selenium, a page is deleted before it is created. My current solution is to wait for a known element in the created page before letting the test continue. This works fine, the page is created followed by its deletion.

Zooming in on the Pages.Epsilon.CreateTextPage() statement in the TestMethod:

public void CreateTextPage()
    SelectElement atomTypeDropDown = new SelectElement(createNewPageSelectTypeElement);
    new WebDriverWait(Browser.Driver, TimeSpan.FromSeconds(5000)).Until(ExpectedConditions.ElementIsVisible(By.CssSelector("h1[data-bind*='text: Headline']")));

First question

Is there a better way to ensure that the page is created first then followed by its deletion? Is it possible to wait in some other way?

Problems with the solution

The problem concerns the design of the framework. Obviously I don't want to hardcode the locator to the Wait statement, I want to use the Page Object for the textatompage I already have available ->

public class TextAtomPage
    [FindsBy(How = How.CssSelector, Using = "h1[data-bind*='text: Headline']")]
    public IWebElement headline { get; set; }

I would like to call Pages.TextAtomPage.headline in my wait statement, but the ExpectedConditions takes a By locator as parameter.

Do I have to change how the elements are saved from Pagefactory to By locators?

Is it possible to extract a By locator from a Pagefactory element?

  • One way to tweak your solution could be to make a method that encapsulates the use of WebDriverWait and accepts what it needs as parameters. like waitUntilVisible(driver, css); It doesn't change what your solution is doing, but makes it easier to refactor in the future and encourages re-use of that exact pattern in multiple pages. Where you would put such a method is up to you. In my project, I have a collection of such methods that enables convenient use of various common waiting conditions I use across my project. And keeps the implementation in one place which makes modifications easy
    – Julian
    Jun 9, 2016 at 18:13
  • 1
    Thank you for the feedback! Due to Ajax calls, waiting for a known element seems to at least work compared to waiting for page load. I will keep a method similar to waitUntilVisible(driver, css) in a help class, and then call it in a "waitforpage" method in the page object, saving one element as a By locator which is used there. The waitforpage is then called last for methods that will finish by redirecting to a certain page object.
    – Jakob
    Jun 10, 2016 at 7:29

1 Answer 1


@Jakob - Found you again :)

public void waitForElement(WebElement value)
         // wait for field
         WebDriverWait wait = new WebDriverWait(ad, 60);


Hope this will help ! Take up if you have any questions.

  • Yes, seems correct!
    – Jakob
    Jul 20, 2016 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.