package com.tngtech.jgiven.report.html5;

import static org.assertj.core.api.Assertions.assertThat;

import com.tngtech.jgiven.CurrentStep;
import com.tngtech.jgiven.Stage;
import com.tngtech.jgiven.annotation.ExpectedScenarioState;
import com.tngtech.jgiven.attachment.Attachment;
import com.tngtech.jgiven.attachment.MediaType;
import java.io.File;
import java.util.List;
import org.openqa.selenium.*;

public class Html5AppStage<SELF extends Html5AppStage<?>> extends Stage<SELF> {
    @ExpectedScenarioState
    protected CurrentStep currentStep;

    @ExpectedScenarioState
    protected WebDriver webDriver;

    @ExpectedScenarioState
    protected File targetReportDir;

    protected void takeScreenshot() {
        String base64 = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.BASE64);
        currentStep.addAttachment(Attachment.fromBase64(base64, MediaType.PNG).withTitle("Screenshot"));
    }

    protected WebElement findTagWithName(String tagName) {
        List<WebElement> links = webDriver.findElements(
                By.xpath(String.format("//a/span[contains(@class,'tag') and contains(text(), '%s')]/..", tagName)));
        assertThat(links).isNotEmpty();
        return links.get(0);
    }

}

@@ -396,16 +396,127 @@
 enium.*;
+%0Aimport org.openqa.selenium.support.ui.ExpectedConditions;%0Aimport org.openqa.selenium.support.ui.WebDriverWait;
 %0A%0Apublic
@@ -589,16 +589,83 @@
 SELF%3E %7B%0A
+    private static final int WEBDRIVER_FIND_TIMEOUT_SECONDS = 120;%0A
     @Exp
@@ -1161,72 +1161,27 @@
     
-List%3CWebElement%3E links = webDriver.findElements(%0A               
+By elementLocator =
  By.
@@ -1269,18 +1269,334 @@
 ..%22,
- tagName))
+%0A                                                   tagName));%0A        WebDriverWait timeoutSetter = new WebDriverWait(webDriver, WEBDRIVER_FIND_TIMEOUT_SECONDS);%0A        timeoutSetter.until(ExpectedConditions.visibilityOfElementLocated(elementLocator));%0A%0A        List%3CWebElement%3E links = webDriver.findElements(elementLocator
 );%0A 

Add bigger timeout for xpath element locator