Created
January 2, 2020 02:11
-
-
Save jfisher446/3e47affde4913f942d8a3e12781b2075 to your computer and use it in GitHub Desktop.
Fisher's Java Selenium Helper Library
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
import java.util.concurrent.ScheduledThreadPoolExecutor; | |
class FishSeLib { | |
ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1); | |
public static WebDriver startChromeWithCustomProfile() { | |
System.setProperty("webdriver.chrome.driver", chromedriverPath); | |
ChromeOptions options = new ChromeOptions(); | |
// loading Chrome with my existing profile instead of a temporary profile | |
options.addArguments("user-data-dir=" + chromeProfilePath); | |
driver = new ChromeDriver(options); | |
driver.manage().window().maximize(); | |
return driver; | |
} | |
private void highlightElement(WebElement element) { | |
if (driver instanceof JavascriptExecutor) { | |
((JavascriptExecutor)driver).executeScript("arguments[0].style.border='1.5px solid red'", element); | |
} | |
exec.schedule(new Runnable() { | |
public void run() { | |
((JavascriptExecutor)driver).executeScript("arguments[0].style.border='1.5px solid green'", element); | |
exec.schedule(new Runnable() { | |
public void run() { | |
((JavascriptExecutor)driver).executeScript("arguments[0].style.border='none'", element); | |
} | |
}, 750, TimeUnit.MILLISECONDS); | |
} | |
}, 200, TimeUnit.MILLISECONDS); | |
} | |
private boolean isAttributePresent(WebElement element, String attribute) { | |
Boolean result = false; | |
try { | |
String value = element.getAttribute(attribute); | |
if (value != null){ | |
result = true; | |
} | |
} catch (Exception e) {} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment