All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.magentys.cinnamon.webdriver.WebDriverUtils Maven / Gradle / Ivy

package io.magentys.cinnamon.webdriver;

import org.openqa.selenium.HasCapabilities;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.WrapsDriver;
import org.openqa.selenium.remote.BrowserType;

public final class WebDriverUtils {

    // Suppresses default constructor, ensuring non-instantiability.
    private WebDriverUtils() {
    }

    public static WebDriver unwrapDriver(final WebElement element) {
        return ((WrapsDriver) element).getWrappedDriver();
    }

    public static String getBrowserName(final WebDriver webDriver) {
        return ((HasCapabilities) webDriver).getCapabilities().getBrowserName();
    }

    public static boolean isSafari(final WebDriver webDriver) {
        return BrowserType.SAFARI.equals(getBrowserName(webDriver));
    }

    public static boolean isInternetExplorer(final WebDriver webDriver) {
        return BrowserType.IE.equals(getBrowserName(webDriver));
    }

    public static boolean isPhantomJs(final WebDriver webDriver) {
        return BrowserType.PHANTOMJS.equals(getBrowserName(webDriver));
    }

    public static String getElementXPath(final WebDriver webDriver, final WebElement element) {
        return (String) ((JavascriptExecutor) webDriver).executeScript(
                "gPt=function(c){if(c.id!==''){return'id(\"'+c.id+'\")'}if(c===document.body){return '//'+c.tagName.toLowerCase()}var a=0;var e=c.parentNode.childNodes;for(var b=0;b




© 2015 - 2024 Weber Informatics LLC | Privacy Policy