diff --git a/src/main/java/org/zaproxy/zest/core/v1/ZestClientElement.java b/src/main/java/org/zaproxy/zest/core/v1/ZestClientElement.java index f33942f..e10cafe 100644 --- a/src/main/java/org/zaproxy/zest/core/v1/ZestClientElement.java +++ b/src/main/java/org/zaproxy/zest/core/v1/ZestClientElement.java @@ -3,9 +3,12 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ package org.zaproxy.zest.core.v1; +import java.time.Duration; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; /** An abstract class representing an action on a client element. */ public abstract class ZestClientElement extends ZestClient { @@ -58,7 +61,40 @@ protected WebElement getWebElement(ZestRuntime runtime) throws ZestClientFailExc this, "No client: " + runtime.getVariable(getWindowHandle())); } String elem = runtime.replaceVariablesInString(this.getElement(), false); + String waitForElementToAppear = runtime.getVariable("waitForElementToAppear"); + if (waitForElementToAppear != null && waitForElementToAppear.equals("true")) { + WebDriverWait wait = new WebDriverWait(wd, Duration.ofSeconds(30)); + try { + if ("className".equalsIgnoreCase(type)) { + return wait.until( + ExpectedConditions.visibilityOfElementLocated(By.className(elem))); + } else if ("cssSelector".equalsIgnoreCase(type)) { + return wait.until( + ExpectedConditions.visibilityOfElementLocated(By.cssSelector(elem))); + } else if ("id".equalsIgnoreCase(type)) { + return wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(elem))); + } else if ("linkText".equalsIgnoreCase(type)) { + return wait.until( + ExpectedConditions.visibilityOfElementLocated(By.linkText(elem))); + } else if ("name".equalsIgnoreCase(type)) { + return wait.until(ExpectedConditions.visibilityOfElementLocated(By.name(elem))); + } else if ("partialLinkText".equalsIgnoreCase(type)) { + return wait.until( + ExpectedConditions.visibilityOfElementLocated( + By.partialLinkText(elem))); + } else if ("tagName".equalsIgnoreCase(type)) { + return wait.until( + ExpectedConditions.visibilityOfElementLocated(By.tagName(elem))); + } else if ("xpath".equalsIgnoreCase(type)) { + return wait.until( + ExpectedConditions.visibilityOfElementLocated(By.xpath(elem))); + } + throw new ZestClientFailException(this, "Unsupported type: " + type); + } catch (Exception e) { + throw new ZestClientFailException(this, e); + } + } try { if ("className".equalsIgnoreCase(type)) { return wd.findElement(By.className(elem));