Skip to content

Instantly share code, notes, and snippets.

#content {
margin: 20px;
}
.block {
margin-top: 10px;
}
.block .btn {
cursor: pointer;
float: left;
margin: 0 10px 10px;
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0-rc.3/handlebars.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/ember.js/1.0.0-rc.6/ember.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
@brobles82
brobles82 / relativeLocatorExample.java
Created January 28, 2020 23:08
basic relative locator
driver.findElement(withTagName("input")
.toRightOf(By.tagName("button")))
.sendKeys("hello");
public boolean isWebElementPresent() {
return driver.findElements(By.testLocator).size() > 0
}
public class NullWebElement implements WebElement {
private NullWebElement() {}
private static NullWebElement instance;
public static NullWebElement getNull() {
if (instance == null) {
instance = new NullWebElement();
}
public WebElement findElement(By by) {
try {
WebDriverWait wait = new WebDriverWait(driver, 5);
return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
} catch (Exception e) {
return NullWebElement.getNull();
}
}
public List<WebElement> findElements(By by) {
public static void click(WebElement webElement) {
WebDriverWait wait = new WebDriverWait(driver(), 30);
ExpectedCondition<Boolean> elementIsClickable = arg0 -> {
try {
webElement.click();
return true;
} catch (Exception e) {
return false;
}
};
public static void click(WebElement webElement) {
String source = driver.getPageSource();
WebDriverWait wait = new WebDriverWait(driver(), 30);
ExpectedCondition<Boolean> elementIsClickable = arg0 -> {
try {
webElement.click();
return !driver.getPageSource().equals(source);
} catch (Exception e) {
public static void type(String text, WebElement webElement) {
if (text == null) {
return;
}
new WebDriverWait(driver(), 30).until((WebDriver) -> {
try {
webElement.clear();
if (webElement.getAttribute("value").length() > 0) {
public class LoginPage {
private final WebDriver webDriver;
@FindBy(linkText = "Log in")
private WebElement login;
@FindBy(id = "username")
private WebElement usernameInput;
@FindBy(id = "password")