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:edu.usc.cs.ir.selenium.handler.GlocktalkBasic.java

License:Apache License

public String processDriver(WebDriver driver) {
    StringBuffer buffer = new StringBuffer();

    // Extract content - getText doesn't return any links
    String content = driver.findElement(By.tagName("body")).getText();
    buffer.append(content).append("\n");

    // Extract threads from a forum
    if (driver.getCurrentUrl().startsWith("http://www.glocktalk.com/forum")) {
        List<WebElement> threadTopics = driver.findElements(By.xpath("//h3[@class='title']"));

        for (WebElement element : threadTopics) {
            WebElement anchor = element.findElement(By.tagName("a"));
            //System.out.println(anchor.getAttribute("href"));
            buffer.append("<a href=\"").append(anchor.getAttribute("href")).append("\" />").append("\n");
        }//from   w  w  w  .  ja v  a  2  s .c om

    }

    // Extract Next Page Link
    List<WebElement> nav = driver.findElements(By.xpath("//div[@class='PageNav']//nav//*[@class='text']"));
    //System.out.println(nav.get(nav.size() - 1).getAttribute("href"));
    if (nav.size() > 0)
        buffer.append("<a href=\"").append(nav.get(nav.size() - 1).getAttribute("href")).append("\" />")
                .append("\n");

    // Extract all links from a thread
    if (driver.getCurrentUrl().startsWith("http://www.glocktalk.com/threads")) {
        List<WebElement> links = driver.findElements(By.xpath("//ol[@id='messageList']//*[@href]"));
        Set<String> filteredLinks = new HashSet<String>();
        for (WebElement link : links) {
            String linkValue = "<a href=\"" + link.getAttribute("href") + "\" />";
            if (linkValue.startsWith("http://www.glocktalk.com/account")
                    || linkValue.startsWith("http://www.glocktalk.com/misc")
                    || linkValue.startsWith("http://www.glocktalk.com/goto")
                    || linkValue.startsWith("http://www.glocktalk.com/social-forums")
                    || linkValue.startsWith("http://www.glocktalk.com/search") || linkValue.contains("#"))
                continue;
            //System.out.println(linkValue);
            filteredLinks.add(linkValue);
        }
        if (filteredLinks.size() > 0)
            buffer.append(filteredLinks).append("\n");
    }
    //System.out.println();
    return buffer.toString();
}

From source file:es.udc.tfg_es.clubtriatlon.test.util.SeleniumMethods.java

License:Open Source License

private static final WebDriver auntenticate(String email, String password) {

    WebDriver driver = new FirefoxDriver();
    driver.get("http://localhost:9090/triatlon/");

    driver.findElement(By.linkText("Autenticarse")).click();
    driver.getCurrentUrl(); //Update the Url
    driver.findElement(By.name("email")).sendKeys(email);
    driver.findElement(By.name("password")).sendKeys(password);
    driver.findElement(By.id("loginForm")).findElement(By.id("loginButton")).click();

    return driver;
}

From source file:es.udc.tfg_es.clubtriatlon.test.web.AdminPlanningWebTest.java

License:Open Source License

@Test
public void testTrainingsManagementView() {

    WebDriver driver = SeleniumMethods.auntenticateAdmin();
    // Access to Planning Weekly view
    driver.findElement(By.id("menuOptions")).findElement(By.id("planningWeekly")).click();
    driver.getCurrentUrl();
    // Access to Trainings Management view
    WebElement trainingsManagementLink = driver.findElement(By.id("trainingsManagement"));
    assertEquals(trainingsManagementLink.getText(), "Gestin de entrenamientos");
    trainingsManagementLink.click();/*w  w  w  . jav  a 2 s.  c om*/
    assertEquals(driver.getCurrentUrl(),
            "http://localhost:9090/triatlon/admin/plannings/trainingsmanagement/0");
    assertEquals(driver.findElement(By.id("menuInfo")).findElement(By.id("menuExplanation")).getText(),
            "- Tipos de entrenamiento");

    SeleniumMethods.logout(driver);
    driver.quit();

}

From source file:es.udc.tfg_es.clubtriatlon.test.web.AdminPlanningWebTest.java

License:Open Source License

@Test
public void testNewWeeklyPlanningView() {

    WebDriver driver = SeleniumMethods.auntenticateAdmin();
    // Access to planningweekly view
    driver.findElement(By.id("menuOptions")).findElement(By.id("planningWeekly")).click();
    driver.getCurrentUrl();
    // Access to New Weekly Planning view
    WebElement newWeeklyPlanningLink = driver.findElement(By.id("newWeeklyPlanning"));
    assertEquals(newWeeklyPlanningLink.getText(), "+ Nuevo plan semanal");
    newWeeklyPlanningLink.click();/*from   w ww. j av  a2 s. c  o m*/
    assertEquals(driver.getCurrentUrl(), "http://localhost:9090/triatlon/admin/plannings/newweeklyplanning");
    //In the page, initially we must see all active trainings with no assigned plannings
    String tableText = driver.findElement(By.cssSelector("table.grid")).getText();
    assertTrue(tableText.contains("training1"));
    assertTrue(tableText.contains("training2"));
    assertTrue(tableText.contains("Triatln base"));
    assertTrue(tableText.contains("Carrera base"));

    SeleniumMethods.logout(driver);
    driver.quit();

}

From source file:es.udc.tfg_es.clubtriatlon.test.web.AdminPlanningWebTest.java

License:Open Source License

@Test
public void testWeeklyPlanningDetailsView() {

    WebDriver driver = SeleniumMethods.auntenticateAdmin();
    // Access to planningweekly view
    driver.findElement(By.id("menuOptions")).findElement(By.id("planningWeekly")).click();
    driver.getCurrentUrl();
    // Access to Weekly Planning Details view
    driver.findElement(By.id("weeksList")).findElement(By.linkText("2015 - s.7")).click();
    assertEquals(driver.getCurrentUrl(),
            "http://localhost:9090/triatlon/admin/plannings/weeklyplanningdetails/7");
    assertEquals(driver.findElement(By.id("menuInfo")).findElement(By.id("menuExplanation")).getText(),
            "- Detalles del plan");

    SeleniumMethods.logout(driver);/*w  w  w.  jav  a2 s  .com*/
    driver.quit();

}

From source file:es.udc.tfg_es.clubtriatlon.test.web.AdminPlanningWebTest.java

License:Open Source License

@Test
public void testWeeklyPlanningDetailsList() {

    WebDriver driver = SeleniumMethods.auntenticateAdmin();
    driver.findElement(By.id("menuOptions")).findElement(By.id("planningWeekly")).click();
    driver.getCurrentUrl();
    driver.findElement(By.id("weeksList")).findElement(By.linkText("2015 - s.7")).click();
    driver.getCurrentUrl();//  w  w w  .  j  ava 2 s.  co m
    String tableText = driver.findElement(By.cssSelector("table.grid")).getText();
    assertTrue(tableText.contains("training1"));
    assertTrue(tableText.contains("training2"));
    assertTrue(tableText.contains("training3"));
    SeleniumMethods.logout(driver);
    driver.quit();

}

From source file:es.udc.tfg_es.clubtriatlon.test.web.AdminPlanningWebTest.java

License:Open Source License

@Test
public void testPlanningWeeklyNextPrevLinks() {

    WebDriver driver = SeleniumMethods.auntenticateAdmin();
    driver.findElement(By.id("menuOptions")).findElement(By.id("planningWeekly")).click();
    driver.getCurrentUrl();

    // Click "-->" link
    driver.findElement(By.id("weeksList")).findElement(By.id("nextLink")).click();
    assertNotNull(driver.findElement(By.id("weeksList")).findElement(By.partialLinkText("2015 - s.2")));
    assertNotNull(driver.findElement(By.id("weeksList")).findElement(By.partialLinkText("2015 - s.1")));

    //Selenium no detecta previousLink porque es por ajax?
    //      driver.getCurrentUrl();
    // Click "<--" link
    //      driver.findElement(By.id("weeksList")).
    //            findElement(By.id("previousLink")).click();
    //      assertNotNull(driver.findElement(By.id("weeksList")).findElement(
    //            By.partialLinkText("2015 - s.7")));

    SeleniumMethods.logout(driver);/* www.j av a  2 s .  co m*/
    driver.quit();

}

From source file:es.udc.tfg_es.clubtriatlon.test.web.RoleWebTest.java

License:Open Source License

@Test
public void testCheckSuccesAuthz() {

    WebDriver driver = SeleniumMethods.auntenticateAdmin();
    //Can see his menu
    WebElement planningLink = driver.findElement(By.id("menuOptions")).findElement(By.id("planningWeekly"));
    assertEquals(planningLink.getText(), "Entrenamientos");
    planningLink.click();/*from  w w w .j av  a 2  s .c  om*/
    assertEquals(driver.getCurrentUrl(), "http://localhost:9090/triatlon/admin/plannings/planningweekly/0");
    SeleniumMethods.logout(driver);
    driver.quit();

}

From source file:fbapi.FBAPI.java

/**
 * @param args the command line arguments
 *//*  w ww. jav  a 2  s .c o  m*/
public static void main(String[] args) {
    // TODO code application logic here
    //https://developers.facebook.com/apps/YOUR_APP_ID/fb-login/
    //https://www.facebook.com/v2.5/dialog/oauth?client_id=XXXXXXXXXXXXXXX&redirect_uri=http%3A%2F%2Fphotovote.dev%2Fauth%2Ffacebook%2Fcallback&scope=email&response_type=code&state=0ztcKhmWwFLtj72TWE8uOKTcf65JmePtG95MZLDD
    //https://www.facebook.com/v2.5/dialog/oauth?client_id=723262031081656&redirect_uri=http://taiwannoc.net/cgione&scope=email&response_type=code&state=0ztcKhmWwFLtj72TWE8uOKTcf65JmePtG95MZLDD
    //https://developers.facebook.com/apps/723262031081656/fb-login/
    /*"http://www.facebook.com/dialog/oauth?" + "client_id="
            + FB_APP_ID + "&redirect_uri="
            + URLEncoder.encode(REDIRECT_URI, "UTF-8")
            + "&scope=public_profile";*/
    //http://www.facebook.com/dialog/oauth?client_id=723262031081656&redirect_uri=http://taiwannoc.net/cgione&scope=public_profile
    String strAPPID = "723262031081656";
    String strRedirectURL = "http://taiwannoc.net/cgione";
    String strAuthUrl = "https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=" + strAPPID
            + "&redirect_uri=" + strRedirectURL + "&scope=user_about_me,"
            + "user_actions.books,user_actions.fitness,user_actions.music,user_actions.news,user_actions.video,user_birthday,user_education_history,"
            + "user_events,user_photos,user_friends,user_games_activity,user_hometown,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_pages,publish_actions,read_insights,user_friends,read_page_mailboxes,rsvp_event";
    System.out.println(strAuthUrl);
    //System.setProperty("webdriver.chrome.driver", "chromedriver");
    System.setProperty("webdriver.chrome.driver", "geckodriver");
    //WebDriver driver = new ChromeDriver();
    WebDriver driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.get(strRedirectURL);
    boolean isRunning = true;
    while (isRunning) {
        System.out.println("CURRENT_URL: " + driver.getCurrentUrl());
        if (driver.getCurrentUrl().contains("facebook.com")) {
            String strURL = driver.getCurrentUrl();
            System.out.println("STR_URL: " + strURL);
            driver.quit();
        }
        isRunning = false;
    }
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandler29.java

License:Apache License

public void processDriver(WebDriver driver) {
    // driver.manage().timeouts().implicitlyWait(10 , TimeUnit.SECONDS);
    String url = driver.getCurrentUrl();
    if (url.contains("outdoorstrader.com/members")) {
        try {/* ww w.  ja v  a2 s .co m*/
            driver.findElement(By.id("ctrl_pageLogin_login")).clear();
            driver.findElement(By.id("ctrl_pageLogin_login")).sendKeys("csci572inforetteam29@gmail.com");
            driver.findElement(By.id("ctrl_pageLogin_password")).clear();
            driver.findElement(By.id("ctrl_pageLogin_password")).sendKeys("crawlparty");
            driver.findElement(By.cssSelector("input.button.primary")).click();
        } catch (Exception e) {

        }
    } else if (url.contains("arguntrader.com/viewforum")) {
        try {
            driver.findElement(By.id("username")).clear();
            driver.findElement(By.id("username")).sendKeys("gead");
            driver.findElement(By.id("password")).clear();
            driver.findElement(By.id("password")).sendKeys("crawlparty");
            driver.findElement(By.id("autologin")).click();
            driver.findElement(By.name("login")).click();
        } catch (Exception e) {

        }
    } else if (url.contains("backpage.com") && !url.contains("www")) {// hacky but should work
        try {
            driver.findElement(By.linkText("sports equip.")).click();
        } catch (Exception e) {

        }
    }
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}