Search in sources :

Example 1 with Rectangle

use of org.openqa.selenium.Rectangle in project page-factory-2 by sbtqa.

the class MobileStepsImpl method press.

/**
 * User make touch action tap on the element's center
 *
 * @param elementTitle title of the element
 */
public T press(String elementTitle) throws PageException {
    WebElement element = Environment.getFindUtils().getElementByTitle(PageContext.getCurrentPage(), elementTitle);
    Rectangle rect = element.getRect();
    int centerX = rect.getX() + rect.getWidth() / 2;
    int centerY = rect.getY() + rect.getHeight() / 2;
    TouchAction touchAction = new TouchAction(Environment.getDriverService().getDriver());
    touchAction.tap(PointOption.point(centerX, centerY)).perform();
    return (T) this;
}
Also used : Rectangle(org.openqa.selenium.Rectangle) WebElement(org.openqa.selenium.WebElement) TouchAction(io.appium.java_client.TouchAction) IOSTouchAction(io.appium.java_client.ios.IOSTouchAction)

Example 2 with Rectangle

use of org.openqa.selenium.Rectangle in project selenium_java by sergueik.

the class BaseTest method highlightNew.

protected void highlightNew(WebElement element, long highlightInterval) {
    Rectangle elementRect = element.getRect();
    String highlightScript = getScriptContent("highlight.js");
    try {
        wait.until(ExpectedConditions.visibilityOf(element));
        if (driver instanceof JavascriptExecutor) {
            ((JavascriptExecutor) driver).executeScript(String.format("%s\nhighlight_create(arguments[0],arguments[1],arguments[2],arguments[3]);", highlightScript), elementRect.y, elementRect.x, elementRect.width, elementRect.height);
        }
        Thread.sleep(highlightInterval);
        if (driver instanceof JavascriptExecutor) {
            ((JavascriptExecutor) driver).executeScript(String.format("%s\nhighlight_remove();", highlightScript));
        }
    } catch (InterruptedException e) {
    // System.err.println("Ignored: " + e.toString());
    }
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Rectangle(org.openqa.selenium.Rectangle)

Example 3 with Rectangle

use of org.openqa.selenium.Rectangle in project carina by qaprosoft.

the class DivisionElementExtractor method getElementsByCoordinates.

@Override
public ExtendedWebElement getElementsByCoordinates(int x, int y) {
    String elementName = String.format("Element founded by x:%d - y:%d", x, y);
    WebDriver driver = getDriver();
    List<WebElement> elements = getEndLevelElements(driver);
    WebElement tempElement;
    int index = 0;
    int isLower;
    Rectangle tempRect;
    while (elements.size() != 1) {
        index = (int) (Math.round(elements.size() / 2f));
        tempElement = elements.get(index);
        tempRect = getRect(tempElement);
        isLower = isLower(tempRect, y);
        LOGGER.debug("Is Lower: " + isLower);
        if (isInside(tempRect, x, y) || isLower == 0) {
            break;
        }
        if (isLower == 1) {
            elements = elements.subList(index, elements.size());
        } else {
            elements = elements.subList(0, index);
        }
    }
    LOGGER.debug("Index: " + index);
    if (elements.size() == 1) {
        return generateExtenedElement(elements, elementName);
    }
    return generateExtenedElement(checkBoundaryElements(elements, x, y, index), elementName);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Rectangle(org.openqa.selenium.Rectangle) WebElement(org.openqa.selenium.WebElement) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement)

Example 4 with Rectangle

use of org.openqa.selenium.Rectangle in project selenium_java by sergueik.

the class Select2WrapperTest method highlightNew.

private void highlightNew(WebElement element, long highlight_interval) {
    Rectangle elementRect = element.getRect();
    String highlightScript = getScriptContent("highlight.js");
    try {
        wait.until(ExpectedConditions.visibilityOf(element));
        if (driver instanceof JavascriptExecutor) {
            ((JavascriptExecutor) driver).executeScript(String.format("%s\nhighlight_create(arguments[0],arguments[1],arguments[2],arguments[3]);", highlightScript), elementRect.y, elementRect.x, elementRect.width, elementRect.height);
        }
        Thread.sleep(highlight_interval);
        if (driver instanceof JavascriptExecutor) {
            ((JavascriptExecutor) driver).executeScript(String.format("%s\nhighlight_remove();", highlightScript));
        }
    } catch (InterruptedException e) {
    // System.err.println("Ignored: " + e.toString());
    }
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Rectangle(org.openqa.selenium.Rectangle)

Example 5 with Rectangle

use of org.openqa.selenium.Rectangle in project carina by qaprosoft.

the class ScreenElementExtractor method getElementsByCoordinates.

@Override
public ExtendedWebElement getElementsByCoordinates(int x, int y) {
    String elementName = String.format("Element founded by x:%d - y:%d", x, y);
    WebDriver driver = getDriver();
    List<WebElement> elements = getEndLevelElements(driver);
    List<WebElement> result = new ArrayList<WebElement>();
    Rectangle rect;
    for (WebElement webElement : elements) {
        try {
            rect = getRect(webElement);
        } catch (Exception e) {
            continue;
        }
        if (isInside(rect, x, y)) {
            result.add(webElement);
        }
    }
    return generateExtenedElement(result, elementName);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) ArrayList(java.util.ArrayList) Rectangle(org.openqa.selenium.Rectangle) WebElement(org.openqa.selenium.WebElement) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement)

Aggregations

Rectangle (org.openqa.selenium.Rectangle)6 WebElement (org.openqa.selenium.WebElement)4 ExtendedWebElement (com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement)3 ArrayList (java.util.ArrayList)2 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)2 WebDriver (org.openqa.selenium.WebDriver)2 TouchAction (io.appium.java_client.TouchAction)1 IOSTouchAction (io.appium.java_client.ios.IOSTouchAction)1