Example usage for org.openqa.selenium.remote RemoteWebDriver findElementById

List of usage examples for org.openqa.selenium.remote RemoteWebDriver findElementById

Introduction

In this page you can find the example usage for org.openqa.selenium.remote RemoteWebDriver findElementById.

Prototype

@Override
    public WebElement findElementById(String using) 

Source Link

Usage

From source file:com.comcast.dawg.house.LoginPageIT.java

License:Apache License

/**
 * @author Kevin Pearson/*from  w  w  w . jav  a 2 s. co  m*/
 * @throws IOException
 */
@Test(description = "Tests if a message explaining that a username was invalid "
        + "becomes visible when the user tries to log in with an invalid username", groups = "uitest")
public void testBadLogin() throws IOException {
    RemoteWebDriver driver = drivers.get();
    String user = "$$$$";

    driver.get(TestServers.getHouse());
    WebElement badLoginMessage = driver.findElementById(LoginPage.BAD_USER_MSG_ID);
    Assert.assertEquals(badLoginMessage.getCssValue("display"), "none");
    loginWithUserName(driver, user);

    String expectedNewPageUrl = TestServers.getHouse();
    Assert.assertEquals(driver.getCurrentUrl(), expectedNewPageUrl);
    badLoginMessage = driver.findElementById(LoginPage.BAD_USER_MSG_ID);
    Assert.assertEquals(badLoginMessage.getCssValue("display"), "block");
}

From source file:com.comcast.dawg.house.LoginPageIT.java

License:Apache License

private void loginWithUserName(RemoteWebDriver driver, String user) {
    driver.findElementById(LoginPage.USER_INPUT_ID).click();
    driver.getKeyboard().sendKeys(user);
    driver.getKeyboard().pressKey(Keys.ENTER);
}

From source file:com.screenslicer.core.scrape.QueryForm.java

License:Open Source License

private static void doSubmit(RemoteWebDriver driver, String formId) throws ActionFailed {
    try {// w ww.ja  v  a  2  s  .c o m
        List<WebElement> inputs = driver.findElementById(formId).findElements(By.tagName("input"));
        List<WebElement> buttons = driver.findElementById(formId).findElements(By.tagName("button"));
        List<WebElement> possibleSubmits = new ArrayList<WebElement>();
        List<WebElement> submits = new ArrayList<WebElement>();
        possibleSubmits.addAll(inputs);
        possibleSubmits.addAll(buttons);
        for (WebElement possibleSubmit : possibleSubmits) {
            if ("submit".equalsIgnoreCase(possibleSubmit.getAttribute("type"))) {
                submits.add(possibleSubmit);
            }
        }
        boolean clicked = false;
        try {
            if (!submits.isEmpty()) {
                if (submits.size() == 1) {
                    clicked = Util.click(driver, submits.get(0));
                } else {
                    String formHtml = CommonUtil.strip(driver.findElementById(formId).getAttribute("outerHTML"),
                            false);
                    int minIndex = Integer.MAX_VALUE;
                    WebElement firstSubmit = null;
                    for (WebElement submit : submits) {
                        try {
                            String submitHtml = CommonUtil.strip(submit.getAttribute("outerHTML"), false);
                            int submitIndex = formHtml.indexOf(submitHtml);
                            if (submitIndex < minIndex) {
                                minIndex = submitIndex;
                                firstSubmit = submit;
                            }
                        } catch (Throwable t) {
                            Log.exception(t);
                        }
                    }
                    if (firstSubmit != null) {
                        clicked = Util.click(driver, firstSubmit);
                    }
                }
            }
        } catch (Throwable t) {
            Log.exception(t);
        }
        if (!clicked) {
            driver.findElementById(formId).submit();
        }
        Util.driverSleepLong();
    } catch (Throwable t) {
        Log.exception(t);
        throw new ActionFailed(t);
    }
}

From source file:com.screenslicer.core.scrape.QueryForm.java

License:Open Source License

public static List<HtmlNode> load(RemoteWebDriver driver, FormLoad context) throws ActionFailed {
    try {//w  w  w.  j  a  v a  2s .  co m
        Util.get(driver, context.site, true);
        Util.doClicks(driver, context.preAuthClicks, null);
        QueryCommon.doAuth(driver, context.credentials);
        Util.doClicks(driver, context.preSearchClicks, null);
        WebElement form = driver.findElementById(context.formId);
        Map<HtmlNode, String> controlsHtml = new HashMap<HtmlNode, String>();
        String formHtml = CommonUtil.strip(form.getAttribute("outerHTML"), false);
        List<WebElement> elements = new ArrayList<WebElement>();
        elements.addAll(form.findElements(By.tagName("input")));
        elements.addAll(form.findElements(By.tagName("button")));
        elements.addAll(form.findElements(By.tagName("textarea")));
        List<HtmlNode> controls = new ArrayList<HtmlNode>();
        for (WebElement element : elements) {
            HtmlNode control = toFormControl(element);
            if (control != null) {
                controls.add(control);
                controlsHtml.put(control, CommonUtil.strip(element.getAttribute("outerHTML"), false));
            }
        }
        elements = new ArrayList<WebElement>();
        elements.addAll(form.findElements(By.tagName("select")));
        for (WebElement element : elements) {
            HtmlNode control = toFormControl(element);
            if (control != null) {
                control.innerHtml = null;
                List<WebElement> options = element.findElements(By.tagName("option"));
                List<String> optionValues = new ArrayList<String>();
                List<String> optionLabels = new ArrayList<String>();
                for (WebElement option : options) {
                    String value = option.getAttribute("value");
                    String label = option.getAttribute("innerHTML");
                    if (!CommonUtil.isEmpty(value) && !CommonUtil.isEmpty(label)) {
                        optionValues.add(value);
                        optionLabels.add(label);
                    }
                }
                String multiple = element.getAttribute("multiple");
                if (!CommonUtil.isEmpty(multiple) && !"false".equalsIgnoreCase(multiple)) {
                    control.multiple = "multiple";
                } else {
                    multiple = element.getAttribute("data-multiple");
                    if (!CommonUtil.isEmpty(multiple) && !"false".equalsIgnoreCase(multiple)) {
                        control.multiple = "multiple";
                    }
                }
                if ("select-multiple".equalsIgnoreCase(control.type)) {
                    control.multiple = "multiple";
                }
                control.type = null;
                control.optionValues = optionValues.toArray(new String[0]);
                control.optionLabels = optionLabels.toArray(new String[0]);
                controls.add(control);
                controlsHtml.put(control, CommonUtil.strip(element.getAttribute("outerHTML"), false));
            }
        }
        loadLabels(driver, controls);
        loadGuids(controls);
        Collections.sort(controls, new ControlComparator(formHtml, controlsHtml));
        return filterControls(controls);
    } catch (Throwable t) {
        Log.exception(t);
        throw new ActionFailed(t);
    }
}

From source file:org.miloss.fgsms.smoke.post.UITest.java

License:Mozilla Public License

private static void login() throws Exception {
    Assume.assumeFalse(drivers.isEmpty());
    //DO login//from w  w w. j  a va  2 s  . c o m
    for (int i = 0; i < drivers.size(); i++) {
        RemoteWebDriver driver = drivers.get(i);
        driver.navigate().to(url);
        driver.findElementByName("username").sendKeys(props.getProperty("fgsmsadminuser"));
        driver.findElementByName("password").sendKeys(props.getProperty("fgsmsadminpass"));
        driver.findElementById("loginButton").click();
        //initial disclaimer
        driver.switchTo().alert().accept();
        if (url.startsWith("http://")) {
            //warning about ssl
            driver.switchTo().alert().accept();
        }

    }
}