Example usage for org.openqa.selenium WebDriver navigate

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

Introduction

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

Prototype

Navigation navigate();

Source Link

Document

An abstraction allowing the driver to access the browser's history and to navigate to a given URL.

Usage

From source file:taurustest.TestUtilities.java

License:Open Source License

public static void clickSettingOptionAndChangeSettings(WebDriver driver, int value)
        throws InterruptedException {
    menuButtonClick(driver);//from w w  w . ja va2s . c  o m
    waitClick(SETTINGS_BUTTON, driver, value);

    String settingLbl = waitGetText(LABEL_SETTINGS, driver, value);
    String versionLbl = waitGetText(LABEL_VERSION, driver, value);
    String notificationLbl = waitGetText(LABEL_NOTIFICATION, driver, value);
    String dataSourceLbl = waitGetText(DATA_SOURCES, driver, value);
    AssertJUnit.assertEquals(settingLbl, "Settings");
    AssertJUnit.assertEquals(versionLbl, "Version");
    AssertJUnit.assertEquals(notificationLbl, "Notifications");
    AssertJUnit.assertEquals(dataSourceLbl, "Data Sources");

    waitClick(REFRESH_RATE, driver, value);
    waitClick(RATE_OPTION, driver, value);
    changeNotificationSettings(driver, value);
    waitClick(CHECK_BOX_FOR_NOTIFICATION, driver, value);
    driver.navigate().back();
}

From source file:test.TinyMce.java

public void run() {
    String contents = this.getContents();// Get Contents
    ResourceHTML baseHtml = new ResourceHTML(basedHtmlOrg);
    baseHtml.insertContent(contents, "td[class=bodyContainer]", HTML);

    if (System.getProperty("webdriver.chrome.driver") == null) {
        System.setProperty("webdriver.chrome.driver", "resources/common/chromedriverMac");
    }//from   w  w w .  j a  v a  2s  .  c o  m

    String workingDir = System.getProperty("user.dir");
    String resourcePath = workingDir + "/resources/common";
    String fileName = "tinymce.html";

    ResourceHTML tinyMCE = new ResourceHTML(resourcePath, fileName);
    tinyMCE.insertContent(baseHtml.getDoc(), "textarea[id=textArea]", HTML);
    HTMLManager.saveHTML(tinyMCE.getDoc(), resourcePath + "/temp.html");

    WebDriver driver = new ChromeDriver();
    Wait<WebDriver> wait = new WebDriverWait(driver, 30);
    driver.get("file://" + resourcePath + "/temp.html");

    JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
    //        
    //        javascriptExecutor.executeScript("arguments[0].innerHTML = '<h1>Set text using innerHTML</h1>'", element);
    //tinyMCE.activeEditor.setContent('<span>some</span> html', {format : 'raw'});
    //        
    //        WebDriver driverDisplay = new ChromeDriver();
    String returnStr = (String) javascriptExecutor
            .executeScript("return tinyMCE.activeEditor.getContent({format : 'raw'});");
    //ResourceHTML contentWithBase = new ResourceHTML(returnStr);
    HTMLManager.saveHTML(returnStr, "temp/temp.html");

    WebDriver displayDriver = new ChromeDriver();
    Wait<WebDriver> wait2 = new WebDriverWait(displayDriver, 30);
    displayDriver.get("file://" + workingDir + "/temp/temp.html");

    while (true) {
        try {
            Thread.sleep(sleepInterval);
            String nextState = (String) javascriptExecutor.executeScript("return nextState()");
            returnStr = (String) javascriptExecutor
                    .executeScript("return tinyMCE.activeEditor.getContent({format : 'raw'});");

            if (nextState.equalsIgnoreCase("save")) {
                Document docToSave = Jsoup.parse(returnStr);
                String saveStr = docToSave.select("td[class=bodyContainer]").html();
                this.setContents(saveStr);

            } else if (nextState.equalsIgnoreCase("close")) {
                driver.quit();
                displayDriver.quit();
                break;
            }
            //System.out.println(returnStr);

            //Insert To baseHTML and Save
            HTMLManager.saveHTML(returnStr, "temp/temp.html");

            displayDriver.navigate().refresh();
        } catch (InterruptedException ex) {
            Logger.getLogger(ChromePreviewThread.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    //
    //        String temp = "test/test.html";
    //        Document doc = Jsoup.parse(returnStr, "UTF-8");
    //        HTMLManager.saveHTML(doc, temp);
    //        driverDisplay.get("file://" + workingDir +"/" +temp);
    //        while (true) {
    //            try{
    //                Thread.sleep(sleepInterval);
    //                returnStr = (String) javascriptExecutor.executeScript("return tinyMCE.activeEditor.getContent({format : 'raw'});");
    //                //System.out.println(returnStr);
    //                
    //                //Insert To baseHTML and Save
    //                baseHtml.insertContent(returnStr, "td[class=bodyContainer]", HTML);
    //                HTMLManager.saveHTML(baseHtml.getDoc(), temp);
    //                
    //                driverDisplay.navigate().refresh();
    //            }catch (InterruptedException ex) {
    //                Logger.getLogger(ChromePreviewThread.class.getName()).log(Level.SEVERE, null, ex);
    //            }
    //        }
}

From source file:testingGR.WaitTool.java

License:Open Source License

/**
 * Wait for an element to appear on the refreshed web-page. And returns the
 * first WebElement using the given method.
 *
 * This method is to deal with dynamic pages.
 * //from  ww w .  j a  v  a 2  s. c om
 * Some sites I (Mark) have tested have required a page refresh to add
 * additional elements to the DOM. Generally you (Chon) wouldn't need to do
 * this in a typical AJAX scenario.
 * 
 * @param WebDriver
 *            The driver object to use to perform this element search
 * @param locator
 *            selector to find the element
 * @param int The time in seconds to wait until returning a failure
 * 
 * @return WebElement the first WebElement using the given method, or
 *         null(if the timeout is reached)
 * 
 * @author Mark Collin
 */
public static WebElement waitForElementRefresh(WebDriver driver, final By by, int timeOutInSeconds) {
    WebElement element;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify
        // implicitlyWait()
        new WebDriverWait(driver, timeOutInSeconds) {
        }.until(new ExpectedCondition<Boolean>() {

            @Override
            public Boolean apply(WebDriver driverObject) {
                driverObject.navigate().refresh(); // refresh the page
                // ****************
                return isElementPresentAndDisplay(driverObject, by);
            }
        });
        element = driver.findElement(by);
        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset
        // implicitlyWait
        return element; // return the element
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:ui.ChromePreviewThread.java

public void run() {
    String editorText = editor.getText();
    //Convert pt to px

    //save//from  w w w .j  ava2 s.  c o  m
    String workingDir = System.getProperty("user.dir");
    String fileName = workingDir + "/temp/temp.html";
    final File f = new File(fileName);

    ResourceHTML baseHtml = new ResourceHTML(basedHtmlOrg);
    baseHtml.insertContent(editorText, "td[class=bodyContainer]", APPEND);
    HTMLManager.saveHTML(baseHtml.getDoc(), fileName);

    //Keep Load/Convert & Refresh
    WebDriver driver = new ChromeDriver();
    Wait<WebDriver> wait = new WebDriverWait(driver, 30);

    driver.get("file://" + fileName);
    //new WebDriverBackedSelenium(driver, "file:///D:/folder/abcd.html");

    //driver.get("http://www.naver.com");
    while (true) {
        if (frame.isVisible() == false) {
            System.out.println("Stopping Thread/Chrome");
            driver.quit();
            return;
        }

        try {
            Thread.sleep(sleepInterval);
            //Get the Text, Save and Refresh
            editorText = editor.getText(); // get
            System.out.println("Thread Running@");

            //Convert PT to Px
            String convertedText = ResourceHTML.convertPtToPxStr(editorText);

            //Inser to BaseHtml and Save
            baseHtml.insertContent(convertedText, "td[class=bodyContainer]", HTML);
            HTMLManager.saveHTML(baseHtml.getDoc(), fileName);

            //Refresh Chrome
            driver.navigate().refresh();

        } catch (InterruptedException ex) {
            Logger.getLogger(ChromePreviewThread.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:Utility.General.java

License:Open Source License

public static void GoTo(WebDriver driver, String url) {

    try {//from  w w w .ja  v  a 2 s.  c  o  m
        URL address = new URL(url);
        driver.navigate().to(address);
    } catch (MalformedURLException ex) {
        Log.log(Level.ERROR, ex.getMessage());
    }

}

From source file:utils.WebDriverUtils.java

public static void refreshPage(WebDriver webDriver) {
    webDriver.navigate().refresh();
}

From source file:webMainScripts.loginLogout.LogoutAndSessionExpiresOnBackButton.java

@Test(priority = 1, groups = { "loginlogout" })
public void LogoutAndSessionExpiresOnBackButtonClick() throws BiffException, IOException, InterruptedException {
    WebDriver d = getBrowser();
    loginLogout = PageFactory.initElements(d, LoginLogoutMethods.class);
    general = PageFactory.initElements(d, WebCommonMethods.class);// initiating the driver and the .class file (the pageObject script)       

    WebCommonMethods.openURL();/*from  w  ww  .java  2  s.  co  m*/

    System.out.println("Checking for LogoutAndSessionExpiresOnBackButton test...");
    LoginLogoutMethods.login("admin");
    Thread.sleep(4000);
    LoginLogoutMethods.logout();

    //session expiry check
    d.navigate().back();
    //System.out.println("Current URL: " + d.getCurrentUrl());
    Assert.assertEquals(d.getCurrentUrl(),
            "http://localhost/orangehrm-3.1.2/orangehrm-3.1.2/symfony/web/index.php/pim/viewEmployeeList");

    Cell[] loginPageLabels = WebCommonMethods.readExcelNextRowOfUniqueValue("webTabsWithSubheading",
            "#loginPage");
    Assert.assertEquals(LoginLogoutMethods.loginPanelHeadingLabel.getText(), loginPageLabels[1].getContents());
}