Example usage for org.openqa.selenium WebDriver findElement

List of usage examples for org.openqa.selenium WebDriver findElement

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver findElement.

Prototype

@Override
WebElement findElement(By by);

Source Link

Document

Find the first WebElement using the given method.

Usage

From source file:com.gargoylesoftware.htmlunit.html.HtmlButton2Test.java

License:Apache License

/**
 * @throws Exception if the test fails// w ww  . j av  a2s. c o m
 */
@Test
@Alerts("2")
public void typeUnknown() throws Exception {
    final String html = "<html><head><title>first</title></head><body>\n" + "  <p>hello world</p>\n"
            + "  <form id='myForm' action='" + URL_SECOND + "'>\n"
            + "    <button type='unknown' id='myButton'>Explicit Submit</button>\n" + "  </form>\n"
            + "</body></html>";
    final String secondContent = "<html><head><title>second</title></head><body>\n" + "  <p>hello world</p>\n"
            + "</body></html>";

    getMockWebConnection().setDefaultResponse(secondContent);

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myButton")).click();

    final int expectedReqCount = Integer.parseInt(getExpectedAlerts()[0]);
    assertEquals(expectedReqCount, getMockWebConnection().getRequestCount());
    if (expectedReqCount > 1) {
        assertEquals(URL_SECOND.toString(), getMockWebConnection().getLastWebRequest().getUrl());
    }
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlButton2Test.java

License:Apache License

/**
 * @throws Exception if the test fails//from ww w. j  a v a 2  s . co m
 */
@Test
public void typeSubmit() throws Exception {
    final String html = "<html><head><title>first</title></head><body>\n" + "  <p>hello world</p>\n"
            + "  <form id='myForm' action='" + URL_SECOND + "'>\n"
            + "    <button type='submit' id='myButton'>Explicit Submit</button>\n" + "  </form>\n"
            + "</body></html>";
    final String secondContent = "<html><head><title>second</title></head><body>\n" + "  <p>hello world</p>\n"
            + "</body></html>";

    getMockWebConnection().setDefaultResponse(secondContent);

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myButton")).click();

    assertEquals(2, getMockWebConnection().getRequestCount());
    assertEquals(URL_SECOND.toString(), getMockWebConnection().getLastWebRequest().getUrl());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlButton2Test.java

License:Apache License

/**
 * @throws Exception if the test fails/*w ww.  j  a v a  2s. co  m*/
 */
@Test
public void typeReset() throws Exception {
    final String html = "<html><head><title>first</title></head><body>\n" + "  <p>hello world</p>\n"
            + "  <form id='myForm' action='" + URL_SECOND + "'>\n"
            + "    <button type='reset' id='myButton'>Explicit Submit</button>\n" + "  </form>\n"
            + "</body></html>";
    final String secondContent = "<html><head><title>second</title></head><body>\n" + "  <p>hello world</p>\n"
            + "</body></html>";

    getMockWebConnection().setDefaultResponse(secondContent);

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myButton")).click();

    assertEquals(1, getMockWebConnection().getRequestCount());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlButton2Test.java

License:Apache License

/**
 * @throws Exception if the test fails/*w  ww .j  av  a 2s  .c o m*/
 */
@Test
public void typeButton() throws Exception {
    final String html = "<html><head><title>first</title></head><body>\n" + "  <p>hello world</p>\n"
            + "  <form id='myForm' action='" + URL_SECOND + "'>\n"
            + "    <button type='button' id='myButton'>Explicit Submit</button>\n" + "  </form>\n"
            + "</body></html>";
    final String secondContent = "<html><head><title>second</title></head><body>\n" + "  <p>hello world</p>\n"
            + "</body></html>";

    getMockWebConnection().setDefaultResponse(secondContent);

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myButton")).click();

    assertEquals(1, getMockWebConnection().getRequestCount());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlButton2Test.java

License:Apache License

/**
 * @throws Exception if the test fails//from   www  .ja v a2  s.co m
 */
@Test
public void typeEmpty() throws Exception {
    final String html = "<html><head><title>first</title></head><body>\n" + "  <p>hello world</p>\n"
            + "  <form id='myForm' action='" + URL_SECOND + "'>\n"
            + "    <button type='button' id='myButton'>Explicit Submit</button>\n" + "  </form>\n"
            + "</body></html>";
    final String secondContent = "<html><head><title>second</title></head><body>\n" + "  <p>hello world</p>\n"
            + "</body></html>";

    getMockWebConnection().setDefaultResponse(secondContent);

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myButton")).click();

    assertEquals(1, getMockWebConnection().getRequestCount());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlButton2Test.java

License:Apache License

/**
 * @throws Exception if the test fails/*from   ww  w  .j  a va  2s .c  o m*/
 */
@Test
@Alerts("2")
public void submitWithoutType() throws Exception {
    final String html = "<html><head><title>first</title></head><body>\n" + "  <p>hello world</p>\n"
            + "  <form id='myForm' action='" + URL_SECOND + "'>\n"
            + "    <button id='myButton'>Implicit Submit</button>\n" + "  </form>\n" + "</body></html>";
    final String secondContent = "<html><head><title>second</title></head><body>\n" + "  <p>hello world</p>\n"
            + "</body></html>";

    getMockWebConnection().setDefaultResponse(secondContent);

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myButton")).click();

    final int expectedReqCount = Integer.parseInt(getExpectedAlerts()[0]);
    assertEquals(expectedReqCount, getMockWebConnection().getRequestCount());
    if (expectedReqCount > 1) {
        assertEquals(URL_SECOND.toString(), getMockWebConnection().getLastWebRequest().getUrl());
    }
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlButton2Test.java

License:Apache License

/**
 * @throws Exception if the test fails/* w w w. j a  v a2 s. co  m*/
 */
@Test
@Alerts(DEFAULT = "2", IE = "1")
public void typeUnknownExternal() throws Exception {
    final String html = "<html><head><title>first</title></head><body>\n" + "  <p>hello world</p>\n"
            + "  <form id='myForm' action='" + URL_SECOND + "'>\n" + "  </form>\n"
            + "  <button type='unknown' id='myButton' form='myForm'>Explicit Submit</button>\n"
            + "</body></html>";
    final String secondContent = "<html><head><title>second</title></head><body>\n" + "  <p>hello world</p>\n"
            + "</body></html>";

    getMockWebConnection().setDefaultResponse(secondContent);

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myButton")).click();

    final int expectedReqCount = Integer.parseInt(getExpectedAlerts()[0]);
    assertEquals(expectedReqCount, getMockWebConnection().getRequestCount());
    if (expectedReqCount > 1) {
        assertEquals(URL_SECOND.toString(), getMockWebConnection().getLastWebRequest().getUrl());
    }
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlButton2Test.java

License:Apache License

/**
 * @throws Exception if the test fails//from  w  ww.  j  av a 2 s. com
 */
@Test
@Alerts(DEFAULT = "2", IE = "1")
public void typeSubmitExternal() throws Exception {
    final String html = "<html><head><title>first</title></head><body>\n" + "  <p>hello world</p>\n"
            + "  <form id='myForm' action='" + URL_SECOND + "'>\n" + "  </form>\n"
            + "  <button type='submit' id='myButton' form='myForm'>Explicit Submit</button>\n"
            + "</body></html>";
    final String secondContent = "<html><head><title>second</title></head><body>\n" + "  <p>hello world</p>\n"
            + "</body></html>";

    getMockWebConnection().setDefaultResponse(secondContent);

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myButton")).click();

    final int expectedReqCount = Integer.parseInt(getExpectedAlerts()[0]);
    assertEquals(expectedReqCount, getMockWebConnection().getRequestCount());
    if (expectedReqCount > 1) {
        assertEquals(URL_SECOND.toString(), getMockWebConnection().getLastWebRequest().getUrl());
    }
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlButton2Test.java

License:Apache License

/**
 * @throws Exception if the test fails//from   w  w  w  .j a  v  a  2  s. co m
 */
@Test
@Alerts("1")
public void typeResetExternal() throws Exception {
    final String html = "<html><head><title>first</title></head><body>\n" + "  <p>hello world</p>\n"
            + "  <form id='myForm' action='" + URL_SECOND + "'>\n" + "  </form>\n"
            + "  <button type='reset' id='myButton' form='myForm'>Explicit Submit</button>\n"
            + "</body></html>";
    final String secondContent = "<html><head><title>second</title></head><body>\n" + "  <p>hello world</p>\n"
            + "</body></html>";

    getMockWebConnection().setDefaultResponse(secondContent);

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myButton")).click();

    final int expectedReqCount = Integer.parseInt(getExpectedAlerts()[0]);
    assertEquals(expectedReqCount, getMockWebConnection().getRequestCount());
    if (expectedReqCount > 1) {
        assertEquals(URL_SECOND.toString(), getMockWebConnection().getLastWebRequest().getUrl());
    }
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlButton2Test.java

License:Apache License

/**
 * @throws Exception if the test fails/* w ww .j  a  va 2 s  . com*/
 */
@Test
@Alerts(DEFAULT = "2", IE = "1")
public void submitWithoutTypeExternal() throws Exception {
    final String html = "<html><head><title>first</title></head><body>\n" + "  <p>hello world</p>\n"
            + "  <form id='myForm' action='" + URL_SECOND + "'>\n" + "  </form>\n"
            + "  <button id='myButton' form='myForm'>Implicit Submit</button>\n" + "</body></html>";
    final String secondContent = "<html><head><title>second</title></head><body>\n" + "  <p>hello world</p>\n"
            + "</body></html>";

    getMockWebConnection().setDefaultResponse(secondContent);

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myButton")).click();

    final int expectedReqCount = Integer.parseInt(getExpectedAlerts()[0]);
    assertEquals(expectedReqCount, getMockWebConnection().getRequestCount());
    if (expectedReqCount > 1) {
        assertEquals(URL_SECOND.toString(), getMockWebConnection().getLastWebRequest().getUrl());
    }
}