WebDriverWait until ExpectedCondition ElementVisible

  • 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?

  • @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.

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2