use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.
the class HtmlElement method clickMouse.
@ReplayOnError(waitAfterAction = true)
public void clickMouse() {
Rectangle viewportPosition = detectViewPortPosition();
// always scroll to element so that we can click on it with mouse
setScrollToElementBeforeAction(true);
findElement(true);
outlineElement(getRealElementNoSearch());
Rectangle elementRect = getRect();
Point scrollPosition = ((CustomEventFiringWebDriver) getDriver()).getScrollPosition();
CustomEventFiringWebDriver.leftClicOnDesktopAt(true, elementRect.x + elementRect.width / 2 + viewportPosition.x - scrollPosition.x, elementRect.y + elementRect.height / 2 + viewportPosition.y - scrollPosition.y, SeleniumTestsContextManager.getThreadContext().getRunMode(), SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector());
}
use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.
the class HtmlElement method simulateClick.
/**
* Click with javascript
*/
@ReplayOnError(waitAfterAction = true)
public void simulateClick() {
if (SeleniumTestsContextManager.isWebTest()) {
((CustomEventFiringWebDriver) updateDriver()).updateWindowsHandles();
}
findElement(true);
outlineElement(getRealElementNoSearch());
DriverConfig driverConfig = WebUIDriver.getWebUIDriver(false).getConfig();
String mouseOverScript;
if ((driverConfig.getBrowserType() == BrowserType.FIREFOX && FirefoxDriverFactory.isMarionetteMode()) || driverConfig.getBrowserType() == BrowserType.EDGE || (driverConfig.getBrowserType() == BrowserType.CHROME && driverConfig.getMajorBrowserVersion() >= 75)) {
mouseOverScript = "var event = new MouseEvent('mouseover', {view: window, bubbles: true, cancelable: true}) ; arguments[0].dispatchEvent(event);";
} else {
mouseOverScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}";
}
executeScript(mouseOverScript, getRealElementNoSearch());
WaitHelper.waitForSeconds(2);
String clickScript = "";
if ((driverConfig.getBrowserType() == BrowserType.FIREFOX && FirefoxDriverFactory.isMarionetteMode()) || driverConfig.getBrowserType() == BrowserType.EDGE || (driverConfig.getBrowserType() == BrowserType.CHROME && driverConfig.getMajorBrowserVersion() >= 75)) {
clickScript = "var event = new MouseEvent('click', {view: window, bubbles: true, cancelable: true}) ;" + "arguments[0].dispatchEvent(event);";
} else {
clickScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('click', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onclick');}";
}
executeScript(clickScript, getRealElementNoSearch());
WaitHelper.waitForSeconds(2);
}
use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.
the class HtmlElement method simulateDoubleClick.
@ReplayOnError(waitAfterAction = true)
public void simulateDoubleClick() {
findElement(true);
outlineElement(getRealElementNoSearch());
DriverConfig driverConfig = WebUIDriver.getWebUIDriver(false).getConfig();
String doubleClickScript;
if ((driverConfig.getBrowserType() == BrowserType.FIREFOX && FirefoxDriverFactory.isMarionetteMode()) || driverConfig.getBrowserType() == BrowserType.EDGE || (driverConfig.getBrowserType() == BrowserType.CHROME && driverConfig.getMajorBrowserVersion() >= 75)) {
doubleClickScript = "var event = new MouseEvent('dblclick', {view: window, bubbles: true, cancelable: true}) ;" + "arguments[0].dispatchEvent(event);";
} else {
doubleClickScript = JS_CLICK_DOUBLE;
}
executeScript(doubleClickScript, getRealElementNoSearch());
}
use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.
the class HtmlElement method simulateSendKeys.
@ReplayOnError(waitAfterAction = true)
public void simulateSendKeys(CharSequence... keysToSend) {
findElement(true);
// click on element before sending keys through keyboard
getRealElementNoSearch().click();
executeScript("arguments[0].focus();", getRealElementNoSearch());
DriverConfig driverConfig = WebUIDriver.getWebUIDriver(false).getConfig();
// sendKeysToActiveElement which are not available for firefox and IE
if ((driverConfig.getBrowserType() == BrowserType.FIREFOX && FirefoxDriverFactory.isMarionetteMode()) || driverConfig.getBrowserType() == BrowserType.INTERNET_EXPLORER || driverConfig.getBrowserType() == BrowserType.EDGE || (driverConfig.getBrowserType() == BrowserType.CHROME && driverConfig.getMajorBrowserVersion() >= 75)) {
logger.warn("using specific Marionette method");
executeScript(String.format("arguments[0].value='%s';", keysToSend[0].toString()), getRealElementNoSearch());
} else {
// use keyboard to type
((CustomEventFiringWebDriver) getDriver()).getKeyboard().sendKeys(keysToSend);
}
}
use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.
the class HtmlElement method findHtmlElements.
/**
* Find elements inside this element
*
* @param childBy
* @return List of HtmlElement's based on real WebElement
*/
@ReplayOnError
public List<WebElement> findHtmlElements(By childBy) {
// find the root element
findElement(false, false);
List<WebElement> htmlElements = new ArrayList<>();
List<WebElement> elements = getRealElementNoSearch().findElements(childBy);
// which retries search
if (elements.isEmpty()) {
throw new NoSuchElementException("No elements found for " + childBy.toString());
}
for (int i = 0; i < elements.size(); i++) {
// frame set to null as we expect the frames are searched in the parent element
htmlElements.add(new HtmlElement("", childBy, this, i));
}
return htmlElements;
}
Aggregations