Java Code Examples for org.openqa.selenium.WebDriver#get()

The following examples show how to use org.openqa.selenium.WebDriver#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: upload_file.java    From at.info-knowledge-base with MIT License 6 votes vote down vote up
static public void main(String[] args) {
	// Creating webdriver
	System.setProperty("webdriver.ie.driver", "C:\\WORK\\IEDriverServer_Win32_2.37.0\\IEDriverServer.exe");
	WebDriver driver = new InternetExplorerDriver();

// Opening page. In this case - local HTML file.
   	driver.get("file://C:/WORK/test.html");

   	// Find element that uploads file.
   	WebElement fileInput = driver.findElement(By.id("file"));

   	// Set direct path to local file that needs to be uploaded. 
   	// That also can be a direct link to file in web, like - https://www.google.com.ua/images/srpr/logo11w.png
   	fileInput.sendKeys("file://C:/WORK/lenna.png");

   	// find button that sends form and click it.
   	driver.findElement(By.id("submit")).click();

   	// Closing driver and session
   	driver.quit();
}
 
Example 2
Source File: Location2Test.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Test for <tt>replace</tt>.
 * @throws Exception if the test fails
 */
@Test
public void replaceLastInHistory() throws Exception {
    final String startContent = "<html><head><title>First Page</title></head><body></body></html>";

    final String secondContent
        = "<html><head><title>Second Page</title><script>\n"
        + "function doTest() {\n"
        + "  location.replace('" + URL_THIRD + "');\n"
        + "}\n"
        + "</script></head><body onload='doTest()'>\n"
        + "</body></html>";

    final String thirdContent = "<html><head><title>Third Page</title></head><body></body></html>";

    getMockWebConnection().setResponse(URL_SECOND, secondContent);
    getMockWebConnection().setResponse(URL_THIRD, thirdContent);

    final WebDriver driver = loadPageWithAlerts2(startContent);
    driver.get(URL_SECOND.toExternalForm());

    assertTitle(driver, "Third Page");

    // navigate back
    driver.navigate().back();
    assertTitle(driver, "First Page");
}
 
Example 3
Source File: GitCrawler.java    From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void openPagedSearchResult(WebDriver driver, int page){
    //Java projects, Most Stars
    String search =  "search?l=&o=desc&p="+page+"&q=language%3AJava&ref=advsearch&s=stars&type=Repositories&utf8=✓";

    driver.get(github + search);

    sleep(6000);
}
 
Example 4
Source File: GoogleTest.java    From adf-selenium with Apache License 2.0 5 votes vote down vote up
/**
 * Most basic Selenium example that searches for a term on google.
 * Does not close the browser on test completion to keep the test as simple as possible.
 */
@Test
public void simpleTest() {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://google.com/?hl=en");
    WebElement searchBox = driver.findElement(name("q"));
    searchBox.sendKeys("adf selenium");
    searchBox.submit();
}
 
Example 5
Source File: InternetExplorerDriverTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
@NoDriverBeforeTest
public void canStartMultipleIeDriverInstances() {
  WebDriver firstDriver = newIeDriver();
  WebDriver secondDriver = newIeDriver();
  try {
    firstDriver.get(pages.xhtmlTestPage);
    secondDriver.get(pages.formPage);
    assertThat(firstDriver.getTitle()).isEqualTo("XHTML Test Page");
    assertThat(secondDriver.getTitle()).isEqualTo("We Leave From Here");
  } finally {
    firstDriver.quit();
    secondDriver.quit();
  }
}
 
Example 6
Source File: WebSocketTest.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception if the test fails
 */
@Test
public void listener() throws Exception {
    startWebServer("src/test/resources/com/gargoylesoftware/htmlunit/javascript/host",
            null, null, new EventsWebSocketHandler());
    try {
        final WebDriver driver = getWebDriver();
        final int[] webSocketCreated = {0};

        if (driver instanceof HtmlUnitDriver) {
            final WebClient webClient = getWebWindowOf((HtmlUnitDriver) driver).getWebClient();
            final WebClientInternals internals = webClient.getInternals();

            internals.addListener(new WebClientInternals.Listener() {
                @Override
                public void webSocketCreated(final WebSocket webSocket) {
                    webSocketCreated[0]++;
                }
            });
        }

        driver.get(URL_FIRST + "WebSocketTest_listener.html");

        if (driver instanceof HtmlUnitDriver) {
            final long maxWait = System.currentTimeMillis() + DEFAULT_WAIT_TIME;
            while (webSocketCreated[0] < 0 && System.currentTimeMillis() < maxWait) {
                Thread.sleep(30);
            }
            assertEquals(1, webSocketCreated[0]);
        }
    }
    finally {
        stopWebServers();
    }
}
 
Example 7
Source File: CheeseFinderTests.java    From SeleniumBestPracticesBook with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindSomeCheese() throws Exception{
  WebDriver selenium = new FirefoxDriver();

  selenium.get("http://awful-valentine.com/");
  selenium.findElement(By.id("searchinput")).clear();
  selenium.findElement(By.id("searchinput")).sendKeys("cheese");
  selenium.findElement(By.id("searchsubmit")).click();
  assertTrue(selenium.findElement(By.className("entry")).getText().contains("No Results Found"));

  selenium.quit();
}
 
Example 8
Source File: GenericWithScreenshotTest.java    From selenium-jupiter with Apache License 2.0 5 votes vote down vote up
@Test
void screenshotGenericTest(WebDriver arg0) {
    arg0.get("https://bonigarcia.github.io/selenium-jupiter/");
    assertThat(arg0.getTitle(),
            containsString("JUnit 5 extension for Selenium"));

    imageFile = new File("screenshotGenericTest_arg0_CHROME_76.0_"
            + ((RemoteWebDriver) arg0).getSessionId() + ".png");
}
 
Example 9
Source File: GetXmlPageObject.java    From PatatiumWebUi with Apache License 2.0 5 votes vote down vote up
public  static void getXmlPageObject()
{
	WebDriver driver=new FirefoxDriver();
	driver.get("http://192.168.0.29:9020/hospital/load");
	String tString=driver.getPageSource();
	System.out.println(tString);
}
 
Example 10
Source File: GeckoDriverExample.java    From journaldev with MIT License 5 votes vote down vote up
public static void main(String[] args) {
	//specify the location of GeckoDriver for Firefox browser automation
	System.setProperty("webdriver.gecko.driver", "geckodriver");
	WebDriver driver = new FirefoxDriver();
	driver.get("https://journaldev.com");
	String PageTitle = driver.getTitle();
	System.out.println("Page Title is:" + PageTitle);
	driver.close();
}
 
Example 11
Source File: DifferentBrowsersConcurrentTest.java    From selenium-jupiter with Apache License 2.0 4 votes vote down vote up
void exercise(WebDriver driver) {
    driver.get("https://bonigarcia.github.io/selenium-jupiter/");
    assertThat(driver.getTitle(),
            containsString("JUnit 5 extension for Selenium"));
}
 
Example 12
Source File: WebClient7Test.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
private void urlEncoding(final boolean header, final String charset,
        final String addHeader,
        final String addHtml,
        final boolean click) throws Exception {
    String html = "<html>\n"
            + "<head><title>foo</title>\n";
    if (!header) {
        html += "  <meta http-equiv='Content-Type' content='text/html; charset=" + charset + "'>\n";
    }
    if (addHeader != null) {
        html += addHeader + "\n";
    }

    html += "</head>\n"
            + "<body>\n"
            + addHtml + "\n"
            + "</body></html>";

    String firstResponse = "HTTP/1.1 200 OK\r\n"
            + "Content-Length: " + html.length() + "\r\n"
            + "Content-Type: text/html";
    if (header) {
        firstResponse += "; charset=" + charset;
    }
    firstResponse += "\r\n"
            + "Connection: close\r\n"
            + "\r\n" + html;

    final String secondResponse = "HTTP/1.1 404 Not Found\r\n"
            + "Content-Length: 0\r\n"
            + "Connection: close\r\n"
            + "\r\n";

    shutDownAll();
    try (PrimitiveWebServer primitiveWebServer =
            new PrimitiveWebServer(Charset.forName(charset), firstResponse, secondResponse)) {
        final String url = "http://localhost:" + primitiveWebServer.getPort() + "/";
        final WebDriver driver = getWebDriver();

        driver.get(url);
        try {
            if (click) {
                driver.findElement(By.id("myLink")).click();
            }

            String reqUrl = primitiveWebServer.getRequests().get(1);
            reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1);

            assertEquals(getExpectedAlerts()[0], reqUrl);
        }
        catch (final WebDriverException e) {
            assertEquals(getExpectedAlerts()[0], "WebDriverException");
        }
    }
}
 
Example 13
Source File: BrowserPageNavigation.java    From webtau with Apache License 2.0 4 votes vote down vote up
public static void open(WebDriver driver, String passedUrl, String fullUrl) {
    driver.get(fullUrl);
    onOpenedPage(passedUrl, fullUrl, driver.getCurrentUrl());
}
 
Example 14
Source File: OutReport.java    From PatatiumWebUi with Apache License 2.0 4 votes vote down vote up
@BeforeTest
public void outReport()
{
	WebDriver driver=new FirefoxDriver();
	driver.get("http://127.0.0.1");
}
 
Example 15
Source File: GenericTest.java    From selenium-jupiter with Apache License 2.0 4 votes vote down vote up
@Test
void genericTest(WebDriver driver) {
    driver.get("https://bonigarcia.github.io/selenium-jupiter/");
    assertThat(driver.getTitle(),
            containsString("JUnit 5 extension for Selenium"));
}
 
Example 16
Source File: ResetPasswordPage.java    From mamute with Apache License 2.0 4 votes vote down vote up
public ResetPasswordPage(WebDriver driver, String url) {
    super(driver);
    driver.get(url);
}
 
Example 17
Source File: LoginPage.java    From dropwizard-experiment with MIT License 4 votes vote down vote up
public static LoginPage go(WebDriver driver) {
    driver.get(UiIntegrationTest.BASE_URL);
    return new LoginPage(driver);
}
 
Example 18
Source File: RemoteWebDriverJupiterTest.java    From selenium-jupiter with Apache License 2.0 4 votes vote down vote up
void exercise(WebDriver driver) {
    driver.get("https://bonigarcia.github.io/selenium-jupiter/");
    assertThat(driver.getTitle(),
            containsString("JUnit 5 extension for Selenium"));
}
 
Example 19
Source File: AllPostsPage.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 4 votes vote down vote up
public AllPostsPage(WebDriver driver) {
    this.driver = driver;
    driver.get("http://demo-blog.seleniumacademy.com/wp/wp-admin/edit.php");
}
 
Example 20
Source File: DockerEdgeJupiterTest.java    From selenium-jupiter with Apache License 2.0 4 votes vote down vote up
@Test
public void testEdge(@DockerBrowser(type = EDGE) WebDriver driver) {
    driver.get("https://bonigarcia.github.io/selenium-jupiter/");
    assertThat(driver.getTitle(),
            containsString("JUnit 5 extension for Selenium"));
}