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:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.PageNavigation.PageNavigation3.java

License:Apache License

public void processDriver(WebDriver driver) {
    try {// ww  w. j a v a 2s .c  o m

        System.out.println("Page title is: " + driver.getTitle());

        String url = driver.getCurrentUrl();
        WebDriverWait wait = new WebDriverWait(driver, 5);
        By targetBy = By.id("");
        By targetPath = By.id("");

        if (url.contains("armslist")) {
            targetBy = By.id("termsagreement");
            targetPath = By.xpath("//button[span='I Agree']");

            WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(targetBy));
            element = element.findElement(targetPath);
            element.click();
        } else if (url.contains("tennesseegunexchange")) {
            System.out.println("url contains msgun!!!!!");
            targetBy = By.id("cw_enter_link");

            WebElement ele = driver.findElement(targetBy);
            Actions action = new Actions(driver);

            action.moveToElement(ele).build().perform();
            ele.click();
        }
    } catch (Exception e) {
        System.out.println(e.toString());
    }

    //System.out.println("=====DEBUG: click success!");

}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.PageNavigation.PageNavigationUK1.java

License:Apache License

public void processDriver(WebDriver driver) {

    if (driver.getCurrentUrl().equalsIgnoreCase("http://www.academy.com/"))
        processDriverForAcademy(driver);
    else if (driver.getCurrentUrl().equalsIgnoreCase("http://www.gandermountain.com/"))
        processDriverForGandermountain(driver);
    else if (driver.getCurrentUrl().equalsIgnoreCase("http://www.hipointfirearmsforums.com/"))
        processDriverForHipointfirearmsforums(driver);
    else if (driver.getCurrentUrl().equalsIgnoreCase("http://www.iwanna.com/"))
        processDriverForIwanna(driver);/*  w  w  w . j ava2s .co  m*/
    else if (driver.getCurrentUrl().equalsIgnoreCase("http://www.lionseek.com/"))
        processDriverForLionseek(driver);
    else if (Pattern.matches("http://www.arguntrader.com/.*", driver.getCurrentUrl()))
        processDriverForArguntrader(driver);

}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.PageNavigation.PageNavigationUK1.java

License:Apache License

public void processDriverForArguntrader(final WebDriver driver) {
    if (driver.getTitle().toLowerCase().contains("login")) {
        WebElement username = driver.findElement(By.id("username"));
        WebElement password = driver.findElement(By.id("password"));
        username.sendKeys("shoot.dexter");
        password.sendKeys("Curious@1234");
        driver.findElement(By.className("button1")).click();

        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }//from www  .  j  a v  a  2s.c o  m
                return d.getCurrentUrl().toLowerCase().contains(driver.getCurrentUrl().toLowerCase());
            }
        });
    }
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java

License:Apache License

public void processImpactGuns(WebDriver driver) {
    if (impactGunList.contains(driver.getCurrentUrl()))
        return;/*from ww  w.j av a2s .c o m*/
    impactGunList.add(driver.getCurrentUrl());
    WebElement nextBut;
    int size = driver
            .findElements(By.xpath(
                    "html/body//a[@id='ctl00_ctl00_MainContent_uxCategory_uxCategoryProductList_TopNextLink']"))
            .size();
    if (size > 0) {
        String str1 = "<html><body><p>";
        while (size > 0) {
            List<WebElement> ele = driver.findElements(By.xpath("html/body//a"));
            for (WebElement we : ele) {
                str1 += "<a href='" + (String) we.getAttribute("href") + "'>" + (String) we.getAttribute("href")
                        + "</a><br>";
            }
            size = driver.findElements(By.xpath(
                    "html/body//a[@id='ctl00_ctl00_MainContent_uxCategory_uxCategoryProductList_TopNextLink']"))
                    .size();
            if (size > 0) {
                nextBut = driver.findElement(By.xpath(
                        "html/body//a[@id='ctl00_ctl00_MainContent_uxCategory_uxCategoryProductList_TopNextLink']"));
                String disabledText = nextBut.getAttribute("disabled");
                if (disabledText == null)
                    driver.findElement(By.xpath(
                            "html/body//a[@id='ctl00_ctl00_MainContent_uxCategory_uxCategoryProductList_TopNextLink']"))
                            .click();
                else
                    break;
            }
        }
        str1 += "</p></body></html>";
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("document.body.innerHTML=arguments[0]", str1);
    }
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java

License:Apache License

public void argunTrader(WebDriver driver) {
    String URL = driver.getCurrentUrl();
    driver.manage().window().maximize();
    //To click the login button in the home screen
    if (URL.equals("http://www.arguntrader.com/")) {
        driver.findElement(By.xpath("/html/body//li[@class='icon-logout']/a")).click();
    }/*from w  w  w.ja va  2 s.  com*/
    //To enter the login details
    WebElement username = driver.findElement(By.id("username"));
    username.sendKeys("char12");
    WebElement password = driver.findElement(By.id("password"));
    password.sendKeys("charan");
    //To click the login button
    driver.findElement(By.xpath("/html/body//dd/input[@class='button1']")).click();
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java

License:Apache License

public void processDriver(WebDriver driver) {
    String url = driver.getCurrentUrl();
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    // Charan/*from  w  ww . j a  v a 2s  .c  om*/
    if (url.matches("^http://([a-zA-Z0-9]+.)*armslist.com/classifieds/\\S*")) {
        processArmsList(driver);
    }

    if (url.matches("^http://([a-zA-Z0-9]+.)*impactguns.com/\\S+.aspx")) {
        processImpactGuns(driver);
    }

    if (url.matches("^http://([a-zA-Z0-9]+.)*iwanna.com/\\S*")) {
        processIwana(driver);
    }

    if (url.matches("^http://([a-zA-Z0-9]+.)*budsgunshop.com/\\S*")) {
        processBudgunshop(driver);
    }

    if (url.matches("^http://([a-zA-Z0-9]+.)*buyusedguns.net/\\S*")) {
        processBuyusedguns(driver);
    }

    if (url.matches("^http://([a-zA-Z0-9]+.)*cheaperthandirt.com/\\S*")) {
        processCheaperthandirt(driver);
    }

    if (url.matches("^http://([a-zA-Z0-9]+.)*davidsonsinc.com/\\S*") && processDavidSonic) {
        int size = driver.findElements(By.xpath("html/body//div[9]/a")).size();
        if (size > 0) {
            driver.findElement(By.xpath("html/body//div[9]/a")).click();
        }
        processDavidSonic = false;
    }
    //charan ends
    //sharan
    if (url.matches("^http://([a-zA-Z0-9]+.)*boards.4chan.org/k/\\S*")) {
        process4chan(driver);
    }
    if (url.matches("^http://([a-zA-Z0-9]+.)*tennesseegunexchange.com/\\S*")) {
        processtenness(driver);
    }
    if (url.matches(
            "^http://([a-zA-Z0-9]+.)*zidaho.com/category/(\\S*gun\\S*)|(\\S*Rifle\\S*)|(\\S*Ammunition\\S*)|(\\S*arms\\S*)|(\\S*Black-Powder\\S*)")) {
        processzidaho(driver);
    }
    if (url.matches("^http://([a-zA-Z0-9]+.)*dallasguns.com/\\S*")) {
        processdallasguns(driver);
    }
    if (url.matches("^http://([a-zA-Z0-9]+.)*elpasoguntrader.com/\\S*")) {
        processelpaso(driver);
    }
    if (url.matches("^http://([a-zA-Z0-9]+.)*floridaguntrader.com/\\S*")) {
        processfloridagun(driver);
    }
    if (url.matches("^http://([a-zA-Z0-9]+.)*iguntrade.com/\\S*")) {
        processigun(driver);
    }
    if (url.matches("^http://([a-zA-Z0-9]+.)*gandermountain.com/guns/\\S*")) {
        processgander(driver);
    }
    // sharan ends
    // rakshith
    if (url.matches("^http://([a-zA-Z0-9]+.)*gunlistings.org/ohio-gun-classifieds/\\S*")) {
        processGunListingsOhio(driver);
    }

    if (url.matches("^http://([a-zA-Z0-9]+.)*wikiarms.com/\\S*")) {
        processWikiArms(driver);
    }

    if (url.matches("^http://([a-zA-Z0-9]+.)*nextechclassifieds.com/\\S*")) {
        processNextechClassifieds(driver);
    }

    if (url.matches("^http://([a-zA-Z0-9]+.)*shooterswap.com/\\S*")) {
        processShooterSwap(driver);
    }

    if (url.matches("^http://([a-zA-Z0-9]+.)*slickguns.com/\\S*")) {
        processSlickGuns(driver);
    }

    if (url.matches("^http://([a-zA-Z0-9]+.)*gunlistings.org/\\S*")) {
        processGunListings(driver);
    }
    // rakshith ends
    // Mithun
    if (url.matches("^http://([a-zA-Z0-9]+.)*arguntrader.com/\\S*")) {
        argunTrader(driver);
    }

    if (url.matches("^http://([a-zA-Z0-9]+.)*vci-classifieds.com/\\S*")) {
        vci_classifieds(driver);
    }
    // Mithun ends
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler6.java

License:Apache License

public void processDriver(WebDriver driver) {
    //This is used to fetch the current url that the Selenium driver is crawling at the moment
    String url = driver.getCurrentUrl();

    System.out.println("Search Pagination");
    System.out.println(url);/*from ww  w.  ja  va  2  s. c  o  m*/

    //checking if the current url matches the budsgunshop.com url
    if (driver.getCurrentUrl().equals("http://www.budsgunshop.com/catalog/index.php")) {
        //We punch in guns in the search field and press enter
        driver.findElement(By.name("keywords")).sendKeys("guns\n");

        System.out.println("handler called team 6 search pagination");

        //Error-handling is done to catch the errors thrown by findElement after evaluating
        try {

            int i = 1;

            //By xpath we check if the title equals "Next Page"
            WebElement next = driver.findElement(By.xpath("//*[@title = ' Next Page ']"));

            do {
                if (next != null) {
                    //if "Next Page" exists if it will click it and crawl and the new page
                    System.out.println("Pagination::nextFound " + i);
                    next.click();
                } else {
                    break;
                }
                //setting the value of variable next to the "Next Page" value
                next = driver.findElement(By.xpath("//*[@title = ' Next Page ']"));
                ++i;

                Thread.sleep(500);
            } while (next != null);

        } catch (NoSuchElementException e)
        //one of the most common exception found was NoSuchElementException and that is why we handled that
        {
            System.out.println("Pagination::nextNotFound.");
        } catch (InterruptedException e) {
            //We print out what cause the program to interrupt, if it did.

            System.out.println("Pagination::InterruptedException. " + e.getMessage());
        }
    }

}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler9.java

License:Apache License

public void processDriver(WebDriver driver) {
    List<String> accumulatedData = new ArrayList<>(); //used to keep image tags from each page after click
    boolean paginationFound = false;
    boolean nextPageFound = false;

    System.err//from   ww w.jav a 2s . c  om
            .println("DallasGunsPaginationHandler: Entered default dallasguns.com/guns_online page!!!!!!!!!,");
    String startPage = driver.getCurrentUrl();

    driver.findElement(By.tagName("body")).getAttribute("innerHTML");
    Configuration conf = NutchConfiguration.create();

    try {
        long end = System.currentTimeMillis() + 5000;
        while (System.currentTimeMillis() < end) {
            //Check if this page has pagination element, if so, need to process
            List<WebElement> testDivs = null;
            testDivs = driver.findElements(new By.ById("pagination"));
            if (testDivs != null && testDivs.size() > 0) {
                WebElement paginationTest = testDivs.get(0);
                if (paginationTest != null) {
                    paginationFound = true;
                    System.err.println("DallasGunsPaginationHandler: " + driver.getCurrentUrl()
                            + " found pagination!!!!!!!!!!!!!!!!");
                    break;
                }
            }
        }

        WebElement nextPage = null;
        List<WebElement> paginationDivs = null;
        List<WebElement> links = null;
        WebElement span = null;
        if (paginationFound) {
            paginationDivs = driver.findElements(new By.ById("pagination"));
            if (paginationDivs.size() > 0) {
                span = paginationDivs.get(0).findElement(new By.ByTagName("span"));
                if (span != null) {
                    // System.err.println("DallasGunsPaginationHandler: found span!!!!!");

                    links = span.findElements(new By.ByTagName("a"));
                    if (links != null && links.size() > 0) {
                        System.err.println("DallasGunsPaginationHandler: found pagination links!!!!!");
                        nextPage = links.get(links.size() - 1);
                        if (nextPage.getAttribute("title").equals("Next Page")) {
                            System.err.println("DallasGunsPaginationHandler: found Next Page link at "
                                    + driver.getCurrentUrl() + "!!!!!!");
                            nextPageFound = true;
                        }
                    }
                }
            }
        }

        while (nextPageFound) {
            nextPage.click();
            new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3));
            System.err.println("DallasGunsPaginationHandler: Arrived at new URL: " + driver.getCurrentUrl()
                    + " from click!!!!!!!");

            List<WebElement> imgs = driver.findElements(new By.ByTagName("img"));

            if (imgs != null && imgs.size() > 0) {
                System.err.println("DallasGunsPaginationHandler: Found new Images at " + driver.getCurrentUrl()
                        + "!!!!!!!");
                for (int j = 0; j < imgs.size(); j++) {
                    String newImgSrc = imgs.get(j).getAttribute("src");
                    //String newImageTag = "<a href='"+newImgSrc+"'> another gun img </a>";
                    accumulatedData.add(newImgSrc);
                    //accumulatedData+=newImageTag;
                    System.err.println("DallasGunsPaginationHandler: updated accumulatedData with + "
                            + newImgSrc + "!!!!!!!!!");
                }
            }
            paginationDivs = driver.findElements(new By.ById("pagination"));
            if (paginationDivs.size() > 0) {
                span = paginationDivs.get(0).findElement(new By.ByTagName("span"));
                if (span != null) {
                    // System.err.println("DallasGunsPaginationHandler: found span!!!!!");
                    links = span.findElements(new By.ByTagName("a"));
                    if (links != null && links.size() > 0) {
                        System.err.println("DallasGunsPaginationHandler: found pagination links!!!!!");
                        nextPage = links.get(links.size() - 1);
                        if (nextPage.getAttribute("title").equals("Next Page")) {
                            System.err.println("DallasGunsPaginationHandler: found Next Page link at "
                                    + driver.getCurrentUrl() + "!!!!!!");
                            nextPageFound = true;
                        } else {
                            nextPageFound = false;
                        }
                    } else {
                        nextPageFound = false;
                    }
                } else {
                    nextPageFound = false;
                }
            } else {
                nextPageFound = false;
            }
        }

        if (accumulatedData.size() > 0) { //append images data to driver so that it can be processed by parser
            //navigating back to original page
            driver.get(startPage);
            System.err.println("DallasGunsPaginationHandler: navigated back to start page "
                    + driver.getCurrentUrl() + "!!!!!!");
            new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3));
            System.err.println("DallasGunsPaginationHandler: appending new data!!!!!!!!");
            JavascriptExecutor jsx = (JavascriptExecutor) driver;
            for (String src : accumulatedData) {
                jsx.executeScript("var aTag = document.createElement('a'); aTag.setAttribute('href',\"" + src
                        + "\"); aTag.innerText = \"gun image\"; document.body.appendChild(aTag);");
                //jsx.executeScript("aTag.setAttribute('href','"+src+"');");
                //jsx.executeScript("aTag.innerText = 'gun image');");
                //jsx.executeScript("document.body.appendChild(aTag);");
            }

            //jsx.executeScript("document.body.innerHTML+= "+ accumulatedData+";");
        }

        System.err.println("DallasGunsIndexHandler: Finished Pagination Handler at " + driver.getCurrentUrl()
                + "!!!!!!!!!!!!");

    } catch (Exception e) {
        System.err.println("ERROR: DallasGunsIndexHandler @" + driver.getCurrentUrl() + e.getMessage());
    }

}

From source file:gov.nih.nci.firebird.commons.selenium2.util.FileDownloadUtils.java

License:Open Source License

private static String getDownloadUri(WebDriver driver, WebElement link) {
    String href = link.getAttribute("href");
    return URI.create(driver.getCurrentUrl()).resolve(href).toString();
}

From source file:GUI.AfterLogin.java

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    // TODO add your handling code here:
    String domain = "http://google.com";
    String appId = "1716266622025825";

    String authUrl = "https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=" + appId
            + "&redirect_uri=" + domain + "&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,read_page_mailboxes,rsvp_event";

    System.setProperty("webdirver.chrome.driver", "chromedriver.exe");

    WebDriver driver = new ChromeDriver();
    driver.get(authUrl);/*from   w  w  w  .  ja v  a 2  s  . c o  m*/
    String accessToken;
    while (true) {

        if (!driver.getCurrentUrl().contains("facebook.com")) {
            String url = driver.getCurrentUrl();
            accessToken = url.replaceAll(".*#access_token=(.+)&.*", "$1");
            driver.quit();
            fbClient = new DefaultFacebookClient(accessToken);
            try {
                // Obtem os dados do utilizador
                UserData userdata = new UserData(fbClient);
                user = userdata.getUser("me");
                Interface it = new Interface();

                this.jButton2.setEnabled(true);
                this.jButton3.setEnabled(true);
                this.textField.setEnabled(true);
                this.jComboBox1.setEnabled(true);
                this.jComboBox2.setEnabled(true);
                this.jComboBox3.setEnabled(true);
                this.jLabel3.setEnabled(true);
                this.jLabel4.setEnabled(true);
                this.jLabel7.setEnabled(true);
                this.jLabel11.setEnabled(true);
                this.jButton4.setEnabled(false);
                this.setName(user.getName());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}