use of org.openqa.selenium.NoSuchElementException in project ORCID-Source by ORCID.
the class WebDriverHelper method elementExists.
public boolean elementExists(String page, String elementId) {
//Open the page
webDriver.get(page);
//Find this element
By switchFromLinkLocator = By.id(elementId);
try {
if (webDriver.findElement(switchFromLinkLocator) != null)
return true;
} catch (NoSuchElementException e) {
return false;
}
return false;
}
use of org.openqa.selenium.NoSuchElementException in project opennms by OpenNMS.
the class JmxConfigurationGeneratorIT method configureJMXConnection.
protected void configureJMXConnection(final boolean skipDefaultVM) throws Exception {
final long end = System.currentTimeMillis() + LOAD_TIMEOUT;
final WebDriverWait shortWait = new WebDriverWait(m_driver, 10);
final String skipDefaultVMxpath = "//span[@id='skipDefaultVM']/input";
final boolean selected = waitForElement(By.xpath(skipDefaultVMxpath)).isSelected();
LOG.debug("skipDefaultVM selected: {}", selected);
if (selected != skipDefaultVM) {
waitForElement(By.xpath(skipDefaultVMxpath)).click();
}
// configure authentication
final WebElement authenticateElement = waitForElement(By.id("authenticate"));
if (!authenticateElement.isSelected()) {
authenticateElement.findElement(By.tagName("input")).click();
}
/*
* Sometimes, Vaadin just loses input, or focus. Or both! I suspect it's
* because of the way Vaadin handles events and DOM-redraws itself, but...
* ¯\_(ツ)_/¯
*
* To make sure it really really *really* works, there are multiple layers
* of belt-and-suspenders-and-glue-and-staples:
*
* 1. Click first to ensure the field is focused
* 2. Clear the current contents of the field
* 3. Send the text to the field
* 4. Click it *again* because sometimes this wakes up the event handler
* 5. Do it all in a loop that checks for validation errors, because
* *sometimes* even with all that, it will fail to fill in a field...
* In that case, hit escape to clear the error message and start all
* over and try again.
*/
boolean found = false;
do {
setVaadinValue("authenticateUser", "admin");
setVaadinValue("authenticatePassword", "admin");
// go to next page
waitForElement(By.id("next")).click();
try {
setImplicitWait(1, TimeUnit.SECONDS);
found = shortWait.until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(final WebDriver driver) {
try {
final WebElement elem = driver.findElement(By.cssSelector("div.v-Notification-error h1"));
LOG.debug("Notification error element: {}", elem);
if (elem != null) {
elem.sendKeys(Keys.ESCAPE);
return false;
}
} catch (final NoSuchElementException | StaleElementReferenceException e) {
LOG.warn("Exception while checking for errors message.", e);
}
try {
final Boolean contains = pageContainsText(MBEANS_VIEW_TREE_WAIT_NAME).apply(driver);
LOG.debug("Page contains '{}'? {}", MBEANS_VIEW_TREE_WAIT_NAME, contains);
return contains;
} catch (final Exception e) {
LOG.warn("Exception while checking for next page.", e);
}
return false;
}
});
} catch (final Exception e) {
LOG.debug("Failed to configure authentication and port.", e);
} finally {
setImplicitWait();
}
} while (System.currentTimeMillis() < end && !found);
}
use of org.openqa.selenium.NoSuchElementException in project opennms by OpenNMS.
the class BSMAdminIT method verifyElementNotPresent.
/**
* Verifies that the provided element is not present.
* @param by
*/
private static void verifyElementNotPresent(OpenNMSSeleniumTestCase testCase, final By by) {
new WebDriverWait(testCase.getDriver(), 5).until(ExpectedConditions.not(new ExpectedCondition<Boolean>() {
@Nullable
@Override
public Boolean apply(@Nullable WebDriver input) {
try {
// the default implicit wait timeout is too long, make it shorter
input.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
WebElement elementFound = input.findElement(by);
return elementFound != null;
} catch (NoSuchElementException ex) {
return false;
} finally {
// set the implicit wait timeout back to the value it has been before
input.manage().timeouts().implicitlyWait(LOAD_TIMEOUT, TimeUnit.MILLISECONDS);
}
}
}));
}
use of org.openqa.selenium.NoSuchElementException in project selenium-tests by Wikia.
the class Elements method getElementByText.
public static WebElement getElementByText(List<WebElement> elements, String value) {
WebElement foundElement = null;
for (WebElement element : elements) {
if (element.getText().equalsIgnoreCase(value)) {
foundElement = element;
PageObjectLogging.log("getElementByText", "Element with text: " + value + " is found from the list", true);
break;
}
}
if (foundElement == null) {
throw new NoSuchElementException("Element with text: " + value + " is not found from the list");
}
return foundElement;
}
use of org.openqa.selenium.NoSuchElementException in project selenium-tests by Wikia.
the class Elements method getElementByChildText.
public static WebElement getElementByChildText(List<WebElement> elements, By childBySelector, String value) {
WebElement foundElement = null;
for (WebElement element : elements) {
if (element.findElement(childBySelector).getText().equalsIgnoreCase(value)) {
foundElement = element;
PageObjectLogging.log("getElementByChildText", "Element's child with text: " + value + " is found from the list", true);
break;
}
}
if (foundElement == null) {
throw new NoSuchElementException("Element's child with text: " + value + " is not found from the list");
}
return foundElement;
}
Aggregations