Skip to content

Instantly share code, notes, and snippets.

@gustavomcarmo
Created July 3, 2018 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gustavomcarmo/aef6d969a7bba41ef9102e5351b3a187 to your computer and use it in GitHub Desktop.
Save gustavomcarmo/aef6d969a7bba41ef9102e5351b3a187 to your computer and use it in GitHub Desktop.
Simple Selenium utilitary Java class with a method for waiting a DOM element to be interactable and a method to click an element through Javascript.
package br.com.esign.selenium.utils;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
/**
* Selenium utilitary class
*
*/
public class SeleniumUtils {
public static void waitForElement(WebDriver driver, WebElement element) {
WebDriverWait driverWait = new WebDriverWait(driver, 20);
driverWait.until(ExpectedConditions.visibilityOf(element));
driverWait.until(ExpectedConditions.elementToBeClickable(element));
}
public static void javascriptClick(WebDriver driver, WebElement element) {
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment