Created
July 3, 2018 08:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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