use of org.openqa.selenium.WebDriver in project rstudio by rstudio.
the class MenuNavigator method getMenuItem.
public static WebElement getMenuItem(final WebDriver driver, String level1, String level2, String level3) {
WebElement popupItem = getMenuItem(driver, level1, level2);
Actions action = new Actions(driver);
action.moveToElement(popupItem).build().perform();
// Wait for there to be two popups open (the level1 and level2 menus)
(new WebDriverWait(driver, 1)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
List<WebElement> elements = driver.findElements(By.className("gwt-MenuBarPopup"));
return elements.size() > 1;
}
});
// Get the second popup menu
List<WebElement> elements = driver.findElements(By.className("gwt-MenuBarPopup"));
WebElement menu2popup = elements.get(1);
return findMenuItemByName(menu2popup, level3);
}
use of org.openqa.selenium.WebDriver in project ats-framework by Axway.
the class AbstractRealBrowserDriver method waitForPageLoaded.
public void waitForPageLoaded(WebDriver driver, int timeoutInSeconds) {
/*InternetExplorer is unable to wait for document's readyState to be complete.*/
if (this instanceof com.axway.ats.uiengine.InternetExplorerDriver) {
return;
}
ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return "complete".equals(((JavascriptExecutor) driver).executeScript("return document.readyState"));
}
};
Wait<WebDriver> wait = new WebDriverWait(driver, timeoutInSeconds);
try {
wait.until(expectation);
} catch (Exception e) {
throw new SeleniumOperationException("Timeout waiting for Page Load Request to complete.", e);
}
}
use of org.openqa.selenium.WebDriver in project ats-framework by Axway.
the class HiddenHtmlElementLocator method findElement.
public static HtmlUnitWebElement findElement(UiElement uiElement, String xpathSuffix, boolean verbose) {
HiddenBrowserDriver browserDriver = (HiddenBrowserDriver) uiElement.getUiDriver();
WebDriver webDriver = (WebDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
HtmlNavigator.getInstance().navigateToFrame(webDriver, uiElement);
String xpath = uiElement.getElementProperties().getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR);
String css = uiElement.getElementProperty("_css");
if (xpathSuffix != null) {
xpath += xpathSuffix;
}
List<WebElement> elements = null;
if (!StringUtils.isNullOrEmpty(css)) {
elements = webDriver.findElements(By.cssSelector(css));
} else {
elements = webDriver.findElements(By.xpath(xpath));
}
if (elements.size() == 0) {
throw new ElementNotFoundException(uiElement.toString() + " not found.");
} else if (elements.size() > 1) {
if (verbose) {
log.warn("More than one HTML elements were found having properties " + uiElement.toString() + ".Only the first HTML element will be used.");
}
}
HtmlUnitWebElement element = (HtmlUnitWebElement) elements.get(0);
if (verbose) {
log.info("Found element: " + element.toString());
}
return element;
}
use of org.openqa.selenium.WebDriver in project ats-framework by Axway.
the class RealHtmlElementLocator method findElement.
public static WebElement findElement(UiElement uiElement, String xpathSuffix, boolean verbose) {
AbstractRealBrowserDriver browserDriver = (AbstractRealBrowserDriver) uiElement.getUiDriver();
WebDriver webDriver = (WebDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
HtmlNavigator.getInstance().navigateToFrame(webDriver, uiElement);
String xpath = uiElement.getElementProperties().getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR);
String css = uiElement.getElementProperty("_css");
if (xpathSuffix != null) {
xpath += xpathSuffix;
}
List<WebElement> elements = null;
if (!StringUtils.isNullOrEmpty(css)) {
elements = webDriver.findElements(By.cssSelector(css));
} else {
elements = webDriver.findElements(By.xpath(xpath));
}
if (elements.size() == 0) {
throw new ElementNotFoundException(uiElement.toString() + " not found.");
} else if (elements.size() > 1) {
if (verbose) {
log.warn("More than one HTML elements were found having properties " + uiElement.toString() + ".Only the first HTML element will be used.");
}
}
WebElement element = (WebElement) elements.get(0);
if (verbose) {
log.debug("Found element: " + element.toString());
}
return element;
}
use of org.openqa.selenium.WebDriver in project geode by apache.
the class ScreenshotOnFailureRule method takeScreenshot.
private void takeScreenshot(String screenshotName) {
WebDriver driver = this.webDriverSupplier.get();
if (driver instanceof TakesScreenshot) {
File tempFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
try {
File screenshot = new File("build/screenshots/" + screenshotName + ".png");
FileUtils.copyFile(tempFile, screenshot);
System.err.println("Screenshot saved to: " + screenshot.getCanonicalPath());
} catch (IOException e) {
throw new Error(e);
}
}
}
Aggregations