use of org.openqa.selenium.WebDriverException in project blueocean-plugin by jenkinsci.
the class SmartWebElement method click.
@Override
public void click() {
for (int i = 0; i < RETRY_COUNT; i++) {
try {
WebElement e = getElement();
e.click();
if (i > 0) {
logger.info(String.format("retry click successful for %s", by.toString()));
}
return;
} catch (WebDriverException ex) {
if (ex.getMessage().contains("is not clickable at point")) {
logger.warn(String.format("%s not clickable: will retry click", by.toString()));
logger.debug("exception: " + ex.getMessage());
try {
// typically this is during an animation, which should not take long
Thread.sleep(500);
} catch (InterruptedException ie) {
// ignore
}
} else {
throw ex;
}
}
}
}
use of org.openqa.selenium.WebDriverException in project sonarqube by SonarSource.
the class Retry method execute.
<T> void execute(Runnable action) {
WebDriverException lastError = null;
boolean retried = false;
long start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) < timeoutInMs) {
try {
action.run();
if (retried) {
System.out.println();
}
return;
} catch (StaleElementReferenceException e) {
// ignore
} catch (WebDriverException e) {
lastError = e;
}
retried = true;
System.out.print(".");
}
if (retried) {
System.out.println();
}
if (lastError != null) {
throw lastError;
}
throw new NoSuchElementException("Not found");
}
use of org.openqa.selenium.WebDriverException in project ats-framework by Axway.
the class HiddenHtmlElementUtils method mouseClick.
@PublicAtsApi
public static void mouseClick(HtmlUnitWebElement webElement) {
Method getElementForOperationMethod = null;
boolean getElementForOperationMethodAccessible = false;
Method moveOutIfNeededMethod = null;
boolean moveOutIfNeededMethodAccessible = false;
Method updateActiveElementMethod = null;
boolean updateActiveElementMethodAccessible = false;
try {
// change access modifiers of some methods
getElementForOperationMethod = HtmlUnitMouse.class.getDeclaredMethod("getElementForOperation", Coordinates.class);
getElementForOperationMethodAccessible = getElementForOperationMethod.isAccessible();
getElementForOperationMethod.setAccessible(true);
moveOutIfNeededMethod = HtmlUnitMouse.class.getDeclaredMethod("moveOutIfNeeded", DomElement.class);
moveOutIfNeededMethodAccessible = moveOutIfNeededMethod.isAccessible();
moveOutIfNeededMethod.setAccessible(true);
updateActiveElementMethod = HtmlUnitMouse.class.getDeclaredMethod("updateActiveElement", DomElement.class);
updateActiveElementMethodAccessible = updateActiveElementMethod.isAccessible();
updateActiveElementMethod.setAccessible(true);
// get the target element
HtmlUnitDriver htmlUnitDriver = (HtmlUnitDriver) webElement.getWrappedDriver();
HtmlUnitMouse mouse = (HtmlUnitMouse) htmlUnitDriver.getMouse();
HtmlElement element = (HtmlElement) getElementForOperationMethod.invoke(mouse, webElement.getCoordinates());
moveOutIfNeededMethod.invoke(mouse, element);
if (htmlUnitDriver.isJavascriptEnabled()) {
if (!(element instanceof HtmlInput)) {
element.focus();
}
element.mouseOver();
element.mouseMove();
}
HtmlUnitKeyboard keyboard = (HtmlUnitKeyboard) htmlUnitDriver.getKeyboard();
element.click(keyboard.isShiftPressed(), keyboard.isCtrlPressed(), keyboard.isAltPressed());
updateActiveElementMethod.invoke(mouse, element);
} catch (IOException ioe) {
throw new WebDriverException(ioe);
} catch (ScriptException e) {
// we need only our exception if such exists
Throwable uiEngineException = e.getCause();
while (uiEngineException != null && !uiEngineException.getClass().getName().toLowerCase().contains("com.axway.ats")) {
uiEngineException = uiEngineException.getCause();
}
if (uiEngineException != null) {
throw (RuntimeException) uiEngineException;
}
// Log the exception with level WARN, because in the main Selenium implementation
// (HtmlUnitMouse.click(coordinates)) the exception is even skipped
log.warn("Script error while clicking web element. " + webElement.toString(), e);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (getElementForOperationMethod != null) {
getElementForOperationMethod.setAccessible(getElementForOperationMethodAccessible);
}
if (moveOutIfNeededMethod != null) {
moveOutIfNeededMethod.setAccessible(moveOutIfNeededMethodAccessible);
}
if (updateActiveElementMethod != null) {
updateActiveElementMethod.setAccessible(updateActiveElementMethodAccessible);
}
}
}
use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.
the class FirefoxBrowser method setOptions.
@Override
public void setOptions() {
// to path where executive file of FF is placed
if ("WINDOWS 8".equalsIgnoreCase(System.getProperty("os.name"))) {
System.setProperty("webdriver.firefox.bin", "c:" + File.separator + "Program Files (x86)" + File.separator + "Mozilla Firefox" + File.separator + "Firefox.exe");
}
// Check if user who is running tests have write access in ~/.mozilla dir and home dir
if ("LINUX".equalsIgnoreCase(System.getProperty("os.name"))) {
File homePath = new File(System.getenv("HOME") + File.separator);
File mozillaPath = new File(homePath + File.separator + ".mozilla");
File tmpFile;
if (mozillaPath.exists()) {
try {
tmpFile = File.createTempFile("webdriver", null, mozillaPath);
} catch (IOException ex) {
PageObjectLogging.log("Can't create file", ex, false);
throw new WebDriverException("Can't create file in path: %s".replace("%s", mozillaPath.getAbsolutePath()));
}
} else {
try {
tmpFile = File.createTempFile("webdriver", null, homePath);
} catch (IOException ex) {
PageObjectLogging.log("Can't create file", ex, false);
throw new WebDriverException("Can't create file in path: %s".replace("%s", homePath.getAbsolutePath()));
}
}
tmpFile.delete();
}
firefoxProfile = new FirefoxProfile(new File(ClassLoader.getSystemResource("FirefoxProfiles/Default").getPath()));
if ("true".equals(Configuration.getPageLoadStrategy())) {
firefoxProfile.setPreference("webdriver.load.strategy", "unstable");
}
if ("true".equals(Configuration.getDisableFlash())) {
firefoxProfile.setPreference("plugin.state.flash", 0);
}
}
use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.
the class ImageEditor method cropImage.
public File cropImage(org.openqa.selenium.Point start, org.openqa.selenium.Dimension size, BufferedImage image) {
int width = size.width;
int height = size.height;
File subImg;
try {
subImg = File.createTempFile("screenshot", ".png");
} catch (IOException e) {
throw new WebDriverException(e);
}
if (width < 1) {
width = 1;
}
if (height < 1) {
height = 1;
}
// https://github.com/Wikia/selenium-tests/blob/9d00f02ba24391534a80520908c2973d9e6bed86/src/test/java/com/wikia/webdriver/common/core/imageutilities/Shooter.java#L46
if (start.getX() < 0) {
start.move(0, start.getY());
}
if (start.getY() < 0) {
start.move(start.getX(), 0);
}
BufferedImage dest = image.getSubimage(start.getX(), start.getY(), width, height);
try {
ImageIO.write(dest, "png", subImg);
} catch (IOException e) {
throw new WebDriverException(e);
}
return subImg;
}
Aggregations