Example usage for org.openqa.selenium WebDriver getCurrentUrl

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

Introduction

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

Prototype

String getCurrentUrl();

Source Link

Document

Get a string representing the current URL that the browser is looking at.

Usage

From source file:com.ecofactor.qa.automation.newapp.page.impl.SettingsPageImpl.java

License:Open Source License

/**
 * Gets the URL from phone browser./*from www . j a  v  a2 s  .co m*/
 * @param element the element
 * @return the URL from phone browser
 */
private String getURLFromPhoneBrowser(final String element) {

    setLogString("Get URL from phone browser", true, CustomLogLevel.LOW);
    final boolean elementDisplayed = isDisplayed(getDriver(), By.cssSelector(element), TINY_TIMEOUT);
    String currentURL = "";
    WebDriverWait wait = new WebDriverWait(getDriver(), 10);
    final WebElement faqElement = getElement(getDriver(), By.cssSelector(element), TINY_TIMEOUT);
    if (elementDisplayed == true) {
        final String previousUrl = getDriver().getCurrentUrl();
        faqElement.click();
        getDriver().manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        ExpectedCondition<Boolean> e = new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {

                return (d.getCurrentUrl() != previousUrl);
            }
        };
        wait.until(e);
        currentURL = getDriver().getCurrentUrl();

    }
    return currentURL;
}

From source file:com.ecofactor.qa.automation.newapp.page.impl.ThermostatPageUIImpl.java

License:Open Source License

/**
 * Checks if is click learn more link redirects new window.
 * @return true, if is click learn more link redirects new window
 * @see com.ecofactor.qa.automation.newapp.page.ThermostatPage#isClickLearnMoreLinkRedirectsNewWindow()
 *///from w ww  .j  ava2s  .  c  o m
@Override
public boolean isClickLearnMoreLinkRedirectsNewWindow() {

    boolean pageRedirected = false;
    final String parentWindowHandle = getDriver().getWindowHandle();
    final WebElement errorModeInfoLink = getElement(getDriver(), By.className(ERROR_MODE_INFO), SHORT_TIMEOUT);
    setLogString("Click on error mode info.", true, CustomLogLevel.LOW);
    errorModeInfoLink.click();
    getAction().rejectAlert();
    // tinyWait();

    final Set<String> windowids = getDriver().getWindowHandles();
    final Iterator<String> iter = windowids.iterator();
    iter.next();
    setLogString("Check if new pop up window opens.", true, CustomLogLevel.LOW);
    setLogString("Switch to other window and verify the title", true, CustomLogLevel.HIGH);
    final WebDriver popup = getDriver().switchTo().window((String) iter.next());

    setLogString("Check URL is :http://ecofactor.uservoice.com/", true, CustomLogLevel.HIGH);
    setLogString("URL is :" + popup.getCurrentUrl(), true, CustomLogLevel.HIGH);

    pageRedirected = popup.getCurrentUrl().contains(mobileConfig.get(MobileConfig.LEARN_MORE_LINK)) ? true
            : false;
    popup.close();
    getDriver().switchTo().window(parentWindowHandle);
    return pageRedirected;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Check weather the particular page is Loaded.
 * @param driver the driver//from w  w  w .  j av  a2 s.c  om
 * @param url the url
 * @param timeout the timeout
 * @return boolean
 */
public static boolean isPageLoaded(final WebDriver driver, final String url, final int timeout) {

    boolean ispageLoaded = (new WebDriverWait(driver, timeout)).until(new ExpectedCondition<Boolean>() {
        boolean loaded;

        public Boolean apply(WebDriver d) {

            if (d.getCurrentUrl().equalsIgnoreCase(url))
                loaded = true;
            return loaded;
        }
    });

    return ispageLoaded;
}

From source file:com.epam.jdi.uitests.mobile.appium.preconditions.IPreconditions.java

License:Open Source License

static boolean checkUrl(String uri, WebDriver driver) {
    return driver.getCurrentUrl().matches(".*/" + uri + "(\\?.*)?");
}

From source file:com.esprit.GUI.Login.java

private void fbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fbActionPerformed
    // TODO add your handling code here:
    String accessToken = "";
    System.setProperty("webdriver.chrome.driver", "D:\\security\\chromedriver.exe");

    WebDriver driver = new ChromeDriver();

    driver.get(//from ww w .j  a v  a  2s .  c  om
            "https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=182538538804902&redirect_uri=https://www.google.tn/&scope=user_about_me,"
                    + "user_actions.books,user_actions.fitness,user_actions.music,user_actions.news,user_actions.video,user_activities,user_birthday,user_education_history,"
                    + "user_events,user_friends,user_games_activity,user_groups,user_hometown,user_interests,user_likes,user_location,user_photos,user_relationship_details,"
                    + "user_relationships,user_religion_politics,user_status,user_tagged_places,user_videos,user_website,user_work_history,ads_management,ads_read,email,"
                    + "manage_notifications,manage_pages,publish_actions,read_friendlists,read_insights,read_mailbox,read_page_mailboxes,read_stream,rsvp_event");

    while (true) {
        if (!driver.getCurrentUrl().contains("facebook.com")) {

            String url = driver.getCurrentUrl();
            int state = 0;
            for (int i = 0; i < url.length(); i++) {

                switch (state) {
                case (0): {
                    if (url.charAt(i) == '=') {
                        state = 1;
                    }
                }
                    break;
                case (1): {

                    if (url.charAt(i) == '&') {
                        state = 2;
                    } else {
                        accessToken += url.charAt(i);
                    }

                }
                    break;
                case (2): {
                }
                    break;
                }

            }

            driver.quit();
            System.out.println(accessToken);

            FacebookClient fbClient = new DefaultFacebookClient(accessToken);

            User me = fbClient.fetchObject("me", User.class);

            txt_password.setText(me.getName());
            txt_mail.setText(me.getId());

        }
    }

}

From source file:com.esprit.GUI.Register1.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    String accessToken = "";
    System.setProperty("webdriver.chrome.driver", "D:\\security\\chromedriver.exe");

    WebDriver driver = new ChromeDriver();

    driver.get(/*w  w  w .  java2 s.c o  m*/
            "https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=1685522955036652&redirect_uri=https://www.google.tn/&scope=user_about_me,"
                    + "user_actions.books,user_actions.fitness,user_actions.music,user_actions.news,user_actions.video,user_activities,user_birthday,user_education_history,"
                    + "user_events,user_friends,user_games_activity,user_groups,user_hometown,user_interests,user_likes,user_location,user_photos,user_relationship_details,"
                    + "user_relationships,user_religion_politics,user_status,user_tagged_places,user_videos,user_website,user_work_history,ads_management,ads_read,email,"
                    + "manage_notifications,manage_pages,publish_actions,read_friendlists,read_insights,read_mailbox,read_page_mailboxes,read_stream,rsvp_event");

    while (true) {
        if (!driver.getCurrentUrl().contains("facebook.com")) {

            String url = driver.getCurrentUrl();
            int state = 0;
            for (int i = 0; i < url.length(); i++) {

                switch (state) {
                case (0): {
                    if (url.charAt(i) == '=') {
                        state = 1;
                    }
                }
                    break;
                case (1): {

                    if (url.charAt(i) == '&') {
                        state = 2;
                    } else {
                        accessToken += url.charAt(i);
                    }

                }
                    break;
                case (2): {
                }
                    break;
                }

            }

            driver.quit();
            System.out.println(accessToken);

            FacebookClient fbClient = new DefaultFacebookClient(accessToken);

            User me = fbClient.fetchObject("me", User.class);

            txtno.setText(me.getFirstName());
            txtpr.setText(me.getLastName());
            txtma.setText(me.getEmail());
            pwd.setText(me.getName());
            txtid.setText(me.getId());

        }
    }

}

From source file:com.evidon.areweprivateyet.Crawler.java

License:Open Source License

private void killPopups(String baseWindow, WebDriver driver) {
    // close any new popups.
    for (String handle : driver.getWindowHandles()) {
        if (!handle.equals(baseWindow)) {
            WebDriver popup = driver.switchTo().window(handle);
            log("\tClosing popup: " + popup.getCurrentUrl());
            popup.close();/*  w ww  .j  a  va2 s  . c  om*/

            // TODO: need to see if this breaks when there is a modal.
        }
    }

    driver.switchTo().window(baseWindow);
}

From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.pages.ApplicationCreationPage.java

License:Apache License

public ApplicationCreationPage(WebDriver wd) {
    super(wd);// w ww. ja  v a2s  .  c om
    logger.debug("current url is : " + wd.getCurrentUrl());
    logger.debug("page title : " + wd.getTitle());

    // assert that we are on the right page
    SeleniumUtils.waitForElement(wd, "addAppButton", DEFAULT_AJAX_TIMEOUT);
    if (!wd.findElement(By.tagName("html")).getText().contains("create application")) {
        throw new IllegalStateException("this is not the new application page");
    }
    logger.debug("you are in application creation page");
}

From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.pages.ApplicationsOverviewPage.java

License:Apache License

public ApplicationsOverviewPage(WebDriver wd) {
    super(wd);//from  w  ww .  java2s .co  m
    logger.debug("current url is : " + wd.getCurrentUrl());
    logger.debug("page title : " + wd.getTitle());
    // assert that we are on the right page
    if (!"orange paas - applications overview".equals(wd.getTitle())) {
        throw new IllegalStateException("this is not the aplications page, title page = " + wd.getTitle());
    }
    logger.debug("you are in applications overview page");
}

From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.pages.EnvironmentCreationPage.java

License:Apache License

public EnvironmentCreationPage(WebDriver wd) throws InterruptedException {
    super(wd);//w  w  w  . j ava2  s .  c  o m
    logger.debug("current url is : " + wd.getCurrentUrl());
    logger.debug("page title : " + wd.getTitle());

    // assert that we are on the right page                     create environment
    SeleniumUtils.waitForElement(wd, "addEnvButton", DEFAULT_AJAX_TIMEOUT);
    if (!wd.findElement(By.tagName("html")).getText().contains("create environment")) {
        logger.error(
                "This should contains 'create environment'" + wd.findElement(By.tagName("html")).getText());
        throw new IllegalStateException("this is not the new environment page");
    }
    logger.debug("you are in create environment page");
}