Example usage for org.openqa.selenium By toString

List of usage examples for org.openqa.selenium By toString

Introduction

In this page you can find the example usage for org.openqa.selenium By toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:WebDriverEventHandler.java

License:Open Source License

/**
 * Called before {@link org.openqa.selenium.WebDriver#findElement WebDriver.findElement(...)}, or
 * {@link org.openqa.selenium.WebDriver#findElements WebDriver.findElements(...)}, or {@link org.openqa.selenium.WebElement#findElement
 * WebElement.findElement(...)}, or {@link org.openqa.selenium.WebElement#findElement WebElement.findElements(...)}.
 *
 * @param by//from www .  j av a  2  s . c  o m
 * @param element will be <code>null</code>, if a find method of <code>WebDriver</code> is called.
 * @param driver
 */
@Override
public void beforeFindBy(By by, WebElement element, WebDriver driver) {
    System.out.println("beforeFindBy fired !!" ) ;
    System.out.println(by.toString()) ;
    System.out.println(element.getTagName()) ;
    System.out.println(driver.getPageSource()) ;
}

From source file:WebDriverEventHandler.java

License:Open Source License

/**
 * Called after {@link org.openqa.selenium.WebDriver#findElement WebDriver.findElement(...)}, or
 * {@link org.openqa.selenium.WebDriver#findElements WebDriver.findElements(...)}, or {@link org.openqa.selenium.WebElement#findElement
 * WebElement.findElement(...)}, or {@link org.openqa.selenium.WebElement#findElement WebElement.findElements(...)}.
 *
 * @param by//  www .j av a 2  s  .c om
 * @param element will be <code>null</code>, if a find method of <code>WebDriver</code> is called.
 * @param driver
 */
@Override
public void afterFindBy(By by, WebElement element, WebDriver driver) {
    System.out.println("afterFindBy fired !!" ) ;
    System.out.println(by.toString()) ;
    System.out.println(element.getTagName()) ;
    System.out.println(driver.getPageSource()) ;
}

From source file:ca.nrc.cadc.web.selenium.AbstractTestWebPage.java

License:Open Source License

public WebElement find(final By by) throws Exception {
    try {/*from w w  w .  j  ava  2s. c  o  m*/
        return driver.findElement(by);
    } catch (Throwable e) {
        System.out.println("No element found: " + by.toString());
        return null;
    }
}

From source file:ca.nrc.cadc.web.selenium.AbstractTestWebPage.java

License:Open Source License

protected void hover(final By by) throws Exception {
    waitForElementPresent(by);//from w  w w.j  a  v a2 s .  c o  m
    waitForElementVisible(by);
    waitForElementClickable(by);

    // Wicked hack.  I hate this.
    // jenkinsd 2014.04.10
    //
    if (getInternetBrowserCommand().contains("afari")) {
        final String byString = by.toString();
        final String value = byString.substring(byString.indexOf(":") + 1).trim();
        final String locatorPrefix;
        final String locatorSuffix;

        if (by instanceof By.ById) {
            locatorPrefix = "\"#";
            locatorSuffix = "\"";
        } else if (by instanceof By.ByClassName) {
            locatorPrefix = "\".";
            locatorSuffix = "\"";
        } else if (by instanceof By.ByLinkText) {
            locatorPrefix = "\"a:contains('";
            locatorSuffix = "')\"";
        } else if (by instanceof By.ByName) {
            locatorPrefix = "\"[name='";
            locatorSuffix = "']\"";
        } else {
            locatorPrefix = "\"";
            locatorSuffix = "\"";
        }

        executeJavaScript("$(" + locatorPrefix + value + locatorSuffix + ").hover();");
    } else {
        hover(find(by));
    }
}

From source file:ca.nrc.cadc.web.selenium.AbstractWebApplicationIntegrationTest.java

License:Open Source License

public WebElement find(final By by) {
    try {/* w w  w .j  ava2 s. c  om*/
        return driver.findElement(by);
    } catch (Throwable e) {
        System.err.println("No element found: " + by.toString());
        return null;
    }
}

From source file:ca.nrc.cadc.web.selenium.AbstractWebApplicationIntegrationTest.java

License:Open Source License

public void waitForElementPresent(final By by) throws Exception {
    if (waitUntil(ExpectedConditions.presenceOfElementLocated(by)) == null) {
        fail("Could not find " + by.toString());
    }/* w  ww.j a  v  a  2s  .  c om*/
}

From source file:com.agomezmoron.appiumhandler.AppiumHandledDriver.java

License:Open Source License

/**
 * This method waits for the {@link MobileElement} described by the {@By} selector with a timeout of seconds.
 * @param selector to get the element./*from w  w w . j a va2s  .  c  o m*/
 * @param seconds to wait for (timeout).
 * @param message to send to the log if something happens.
 */
public void waitFor(By selector, long seconds, String message) {
    LOGGER.info("Waiting for " + selector.toString());
    long start = new Date().getTime();
    long end = start + (seconds * 1000);
    long now = new Date().getTime();
    MobileElement element = null;
    do {
        element = this.findElement(selector);
        now = new Date().getTime();
    } while (element == null && now <= end);

    if (element == null) {
        if (message != null && "".equals(message.trim())) {
            LOGGER.error("After waiting " + seconds + " seconds for the element " + selector.toString()
                    + ", the element is missing!. Custom message: " + message);
        } else {
            LOGGER.error("After waiting " + seconds + " seconds for the element " + selector.toString()
                    + ", the element is missing!");
        }
    }
}

From source file:com.agomezmoron.appiumhandler.AppiumHandledDriver.java

License:Open Source License

/**
 * This method waits for the {@link MobileElement} until it's visible described by the {@By} selector with a timeout of seconds.
 * @param selector to get the element.//from www .j av  a 2s . co  m
 * @param seconds to wait for (timeout).
 * @param message to send to the log if something happens.
 */
public void waitUntilVisible(By selector, long seconds, String message) {
    LOGGER.info("Waiting for " + selector.toString());
    this.waitFor(selector, seconds, message);
    MobileElement element = this.findElement(selector);
    if (element != null && !element.isDisplayed()) {
        LOGGER.error("After waiting " + seconds + " seconds for the element " + selector.toString()
                + " exists in the DOM but is not displayed.");
    }
}

From source file:com.amolik.scrapers.OdishaRationCardScraper.java

public static void waitForBlock(WebDriver driver, String districtValue, String blockText) {

    By byText = By.xpath
    //            ("//select["+
    //              "[@id='ddlDistrict']/option[@value='"+districtValue+"']"+
    //              " and "+
    //            " [@id='ddlBlock']/option[text()='"+blockText+"']"+   
    //            "]");
    ("//select[@id='ddlBlock']/option[text()='" + blockText + "']");

    if (logger.isDebugEnabled()) {

        logger.debug("waitForBlock(" + "WebDriver, String, String) - xpath by string=" + byText.toString()); //$NON-NLS-1$
    }//from w ww. ja v a2s  .  c  o  m
    WebElement element = new WebDriverWait(driver, 20)
            .until(ExpectedConditions.presenceOfElementLocated(byText));
}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Finder.java

License:Apache License

private WebElement findElement(By locator) {
    logger.debug("Locating element using " + locator.toString());
    try {//from ww w . ja  v  a2  s  .  c  o m
        return driver.findElement(locator);
    } catch (NoSuchElementException nsee) {
        throw new NoSuchElementException("Unable to locate element using " + locator.toString(), nsee);
    }
}