Example usage for org.openqa.selenium JavascriptExecutor executeScript

List of usage examples for org.openqa.selenium JavascriptExecutor executeScript

Introduction

In this page you can find the example usage for org.openqa.selenium JavascriptExecutor executeScript.

Prototype

Object executeScript(String script, Object... args);

Source Link

Document

Executes JavaScript in the context of the currently selected frame or window.

Usage

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  w  w w  .j ava 2  s.  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 processdallasguns(WebDriver driver) {
    String str1 = "<html><body><p>";
    while (true) {
        int size = driver.findElements(By.xpath("/html/body//div[@id='pagination']/span/a[@title='Next Page']"))
                .size();/*from w  w w  .  j a va 2  s .c  o  m*/
        if (size > 0) {

            List<WebElement> ele = driver.findElements(By.xpath("html/body//a"));
            //List<WebElement> ele2 = driver.findElements(By.xpath("html/body//img"));
            for (WebElement we : ele) {
                str1 += "<a href='" + (String) we.getAttribute("href") + "'>" + (String) we.getAttribute("href")
                        + "</a><br>";
            }
            /*
            for(WebElement we : ele2){
            str1+="<a href='"+(String)we.getAttribute("src")+"'>"+(String)we.getAttribute("src")+"</a><br>";
            } */
            WebElement ele1 = driver
                    .findElement(By.xpath("/html/body//div[@id='pagination']/span/a[@title='Next Page']"));
            //System.out.println(ele1.getAttribute("href"));
            ele1.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 processelpaso(WebDriver driver) {

    String str1 = "<html><body><p>";
    while (true) {
        int size = driver.findElements(By.xpath("/html/body//div[@class='art-pager']/a[@title='Next']")).size();
        if (size > 0) {

            List<WebElement> ele = driver.findElements(By.xpath("html/body//a"));
            // List<WebElement> ele2 = driver.findElements(By.xpath("html/body//img"));
            for (WebElement we : ele) {
                str1 += "<a href='" + (String) we.getAttribute("href") + "'>" + (String) we.getAttribute("href")
                        + "</a><br>";
            }/*w ww .  j a  v a 2 s .c  o m*/
            /*
            for(WebElement we : ele2){
            str1+="<a href='"+(String)we.getAttribute("src")+"'>"+(String)we.getAttribute("src")+"</a><br>";
            }
            */
            WebElement ele1 = driver
                    .findElement(By.xpath("/html/body//div[@class='art-pager']/a[@title='Next']"));
            //System.out.println(ele1.getAttribute("href"));
            ele1.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 processfloridagun(WebDriver driver) {
    String str1 = "<html><body><p>";
    while (true) {
        String s = driver/*w  ww  .j av a 2 s. co m*/
                .findElement(By.xpath(
                        "/html/body//ul[@class='pagination browsing_result_page_links']/li[@class='current']"))
                .getText();
        List<WebElement> ls = driver
                .findElements(By.xpath("/html/body//ul[@class='pagination browsing_result_page_links']/li/a"));
        WebElement wval = null;
        for (WebElement w1 : ls) {
            String wstr = w1.getText();
            if (wstr.matches("[0-9]+")) {
                if (Integer.parseInt(wstr) == (Integer.parseInt(s) + 1)) {
                    wval = w1;
                    break;
                }
            }
        }
        if (wval != null) {
            List<WebElement> ele = driver.findElements(By.xpath("html/body//a"));
            //List<WebElement> ele2 = driver.findElements(By.xpath("html/body//img"));
            for (WebElement we : ele) {
                str1 += "<a href='" + (String) we.getAttribute("href") + "'>" + (String) we.getAttribute("href")
                        + "</a><br>";
            }
            /*
            for(WebElement we : ele2){
            str1+="<a href='"+(String)we.getAttribute("src")+"'>"+(String)we.getAttribute("src")+"</a><br>";
            }
            */
            wval.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 processigun(WebDriver driver) {
    String str1 = "<html><body><p>";
    while (true) {
        int size = driver.findElements(By.xpath("/html/body//li/a[@class='searchPaginationNext list-last']"))
                .size();//from w w w .  ja v  a  2  s . c o  m
        if (size > 0) {
            List<WebElement> ele = driver.findElements(By.xpath("html/body//a"));
            //List<WebElement> ele2 = driver.findElements(By.xpath("html/body//img"));
            for (WebElement we : ele) {
                str1 += "<a href='" + (String) we.getAttribute("href") + "'>" + (String) we.getAttribute("href")
                        + "</a><br>";
            }
            /*
            for(WebElement we : ele2){
            str1+="<a href='"+(String)we.getAttribute("src")+"'>"+(String)we.getAttribute("src")+"</a><br>";
            }
            */
            WebElement ele1 = driver
                    .findElement(By.xpath("/html/body//li/a[@class='searchPaginationNext list-last']"));
            ele1.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 processGunListingsOhio(WebDriver driver) {
    try {//from   w  w  w.j  a  va 2  s.c om
        Select select_item = new Select(driver.findElement(By.name("state")));
        select_item.selectByVisibleText("All States");
        WebElement element = driver.findElement(By.xpath("//*[contains(@name,'search')]"));
        element.click();
        int page = 1;
        String str1 = "<html><body><p>";
        while (true) {
            page++;
            List<WebElement> ele = driver.findElements(By.tagName("a"));
            for (WebElement we : ele) {
                str1 += "<a href='" + (String) we.getAttribute("href") + ">" + (String) we.getAttribute("href")
                        + "</a><br>";
            }
            try {
                // check if the next page is present
                String pagestr = "page=" + page;
                String s1 = "a[href*='" + pagestr + "']";
                WebElement page_num = driver.findElement(By.cssSelector(s1));
                page_num.click();
            } catch (NoSuchElementException ex) {
                // end of pagination
                break;
            }
        }
        JavascriptExecutor js = (JavascriptExecutor) driver;
        str1 += "</p></body></html>";
        js.executeScript("document.body.innerHTML=arguments[0]", str1);
    } catch (NoSuchElementException ex) {
        // pagination not present
    }
}

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

License:Apache License

public void processGunListings(WebDriver driver) {
    try {//from   w w  w  .  java  2  s  . c  om
        WebElement element = driver.findElement(By.xpath("//input[@src='images/search.jpg']"));
        element.click();
        int page = 1;
        String str1 = "<html><body><p>";
        while (true) {
            page++;
            List<WebElement> ele = driver.findElements(By.tagName("a"));
            for (WebElement we : ele) {
                str1 += "<a href='" + (String) we.getAttribute("href") + ">" + (String) we.getAttribute("href")
                        + "</a><br>";
            }
            try {
                // check if the next page is present
                String pagestr = "page=" + page;
                String s1 = "a[href*='" + pagestr + "']";
                WebElement page_num = driver.findElement(By.cssSelector(s1));
                page_num.click();
            } catch (NoSuchElementException ex) {
                break;
            }
        }
        JavascriptExecutor js = (JavascriptExecutor) driver;
        str1 += "</p></body></html>";
        js.executeScript("document.body.innerHTML=arguments[0]", str1);
    } catch (NoSuchElementException ex) {
        // search box not present
        // ex.printStackTrace();
    }
}

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

License:Apache License

public void processWikiArms(WebDriver driver) {
    try {/*from w w  w.j  av a2  s . co m*/
        int page = 1;
        String str1 = "<html><body><p>";
        while (true) {
            page++;
            List<WebElement> ele = driver.findElements(By.tagName("a"));
            for (WebElement we : ele) {
                str1 += "<a href='" + (String) we.getAttribute("href") + ">" + (String) we.getAttribute("href")
                        + "</a><br>";
            }
            try {
                // check if the next page is present
                WebElement page_num = driver.findElement(By.xpath("//a[text()='" + page + "']"));
                page_num.click();
            } catch (NoSuchElementException ex) {
                // end of pagination
                break;
            }
        }
        JavascriptExecutor js = (JavascriptExecutor) driver;
        str1 += "</p></body></html>";
        js.executeScript("document.body.innerHTML=arguments[0]", str1);
    } catch (NoSuchElementException ex) {
        // Pagination not present
    }
}

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

License:Apache License

public void processNextechClassifieds(WebDriver driver) {
    try {//  w w w.  j  a  va  2  s . c  om
        int page = 1;
        String str1 = "<html><body><p>";
        while (true) {
            page++;
            List<WebElement> ele = driver.findElements(By.tagName("a"));
            for (WebElement we : ele) {
                str1 += "<a href='" + (String) we.getAttribute("href") + ">" + (String) we.getAttribute("href")
                        + "</a><br>";
            }
            try {
                // check if the next page is present
                WebElement page_num = driver.findElement(By.xpath("//a[text()='" + page + "']"));
                page_num.click();
            } catch (NoSuchElementException ex) {
                // end of (view more listings)
                break;
            }
        }
        JavascriptExecutor js = (JavascriptExecutor) driver;
        str1 += "</p></body></html>";
        js.executeScript("document.body.innerHTML=arguments[0]", str1);
    } catch (NoSuchElementException ex) {
        // No pagination
    }
}

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

License:Apache License

public void processShooterSwap(WebDriver driver) {
    try {//from  w w w. jav  a  2  s  .c  om
        int page = 1;
        String str1 = "<html><body><p>";
        while (true) {
            page++;
            List<WebElement> ele = driver.findElements(By.tagName("a"));
            for (WebElement we : ele) {
                str1 += "<a href='" + (String) we.getAttribute("href") + ">" + (String) we.getAttribute("href")
                        + "</a><br>";
            }
            try {
                WebElement page_num;
                if (page > 2) {
                    page_num = driver.findElement(By.xpath("//a[text()=' View More Ads ']"));
                } else {
                    page_num = driver.findElement(By.xpath("//a[text()='View More Ads']"));
                }
                page_num.click();
            } catch (NoSuchElementException ex) {
                // end of gun listings
                break;
            }
        }
        JavascriptExecutor js = (JavascriptExecutor) driver;
        str1 += "</p></body></html>";
        js.executeScript("document.body.innerHTML=arguments[0]", str1);
    } catch (NoSuchElementException ex) {
        // View More Ads not recognized
    }
}