Example usage for org.openqa.selenium WebDriver get

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

Introduction

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

Prototype

void get(String url);

Source Link

Document

Load a new web page in the current browser window.

Usage

From source file:glenn.IT_SeleniumTest.java

License:Apache License

@Test
public void seleniumTest() {
    StringBuffer verificationErrors = new StringBuffer();
    String baseUrl = "http://localhost:8090";

    WebDriver driver = new FirefoxDriver();

    driver.get(baseUrl + "/JavaApp-war/");
    driver.findElement(By.id("name")).clear();
    driver.findElement(By.id("name")).sendKeys("Glenn Brown");
    driver.findElement(By.name("Submit")).click();
    // Warning: verifyTextPresent may require manual changes
    try {//from   w  ww  .j a  va2 s . c om
        assertTrue(driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*$"));
    } catch (Error e) {
        verificationErrors.append(e.toString());
    }
}

From source file:GlennsPack.GlennWebAPI.Bot2048.java

License:Open Source License

public Bot2048() {
    System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe");
    WebDriver driver = new ChromeDriver();

    driver.manage().window().setSize(new Dimension(2000, 800));

    driver.get("http://annimon.github.io/16384/");

    //      try {
    //         Thread.sleep(2000);
    //      } catch (Exception e) {
    //         // FIXME: handle exception
    //      }//  w w w .j  ava 2 s .  c  o m
    //      
    WebElement element = driver.findElement(By.xpath("/html/body/div"));
    //            ("/html/body/div/div[2]"));

    Actions actions = new Actions(driver);
    actions.moveToElement(element);
    actions.click();
    CharSequence[] array = { Keys.ARROW_DOWN, Keys.ARROW_LEFT, Keys.ARROW_RIGHT };
    for (int i = 0; i < 1000000; i++) {
        Random random = new Random();
        actions.sendKeys(array[random.nextInt(3)]);
        ;
        actions.sendKeys(Keys.ARROW_DOWN);
        actions.build().perform();
        try {
            //         Thread.sleep(1);
        } catch (Exception e) {
            // FIXME: handle exception
        }
    }
}

From source file:GlennsPack.GlennWebAPI.Example.java

License:Open Source License

public void gojbSpam() {
    System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe");
    WebDriver driver = new ChromeDriver();

    driver.manage().window().setSize(new Dimension(2000, 800));

    driver.get("http://gojb.ml/chat");

    try {/* w  w w  .  j ava2 s. co m*/
        Thread.sleep(500);
    } catch (InterruptedException e1) {
        // FIXME Auto-generated catch block
        e1.printStackTrace();
    }
    driver.findElement(By.xpath("//*[@id=\"menu\"]/div/ul/li[1]/div/p")).click();
    ;
    driver.findElement(By.id("knapp")).click();
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        // FIXME Auto-generated catch block
        e.printStackTrace();
    }
    driver.switchTo().alert().sendKeys("GoJbBot");
    driver.switchTo().alert().accept();
    driver.findElement(By.id("knapp2")).click();
    for (int i = 0; i < 1000; i++) {
        str = "";
        for (int i1 = 0; i1 < 10; i1++) {
            str = str + abc.charAt(rand.nextInt(abc.length()));
        }
        driver.findElement(By.id("chat")).sendKeys(str, Keys.ENTER);
    }
}

From source file:GlennsPack.GlennWebAPI.Example.java

License:Open Source License

public void twitterSpam() {
    System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe");
    WebDriver driver = new ChromeDriver();

    driver.manage().window().setSize(new Dimension(2000, 800));

    driver.get("https://twitter.com/login");

    driver.findElement(By.xpath("//*[@id=\"page-container\"]/div/div[1]/form/fieldset/div[1]/input"))
            .sendKeys("kakansbot");
    driver.findElement(By.xpath("//*[@id=\"page-container\"]/div/div[1]/form/fieldset/div[2]/input"))
            .sendKeys("falcor1122");
    driver.findElement(By.xpath("//*[@id=\"page-container\"]/div/div[1]/form/div[2]/button")).click();

    millisAtStart = System.currentTimeMillis();
    try {//from   w w w  .  j a va2 s  . com

        for (int i = 0; i < 100; i++) {
            str = "";
            for (int i1 = 0; i1 < 10; i1++) {
                str = str + abc.charAt(rand.nextInt(abc.length()));
            }

            driver.findElement(By.xpath("//*[@id=\"global-new-tweet-button\"]")).click();
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                // FIXME Auto-generated catch block
                e.printStackTrace();
            }
            driver.findElement(By.id("tweet-box-global")).sendKeys(str);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                // FIXME Auto-generated catch block
                e.printStackTrace();
            }
            driver.findElement(
                    By.xpath("//*[@id=\"global-tweet-dialog-dialog\"]/div[2]/div[4]/form/div[2]/div[2]/button"))
                    .click();
            x++;
            System.out.println("Nu har " + x + " tweets skickats, "
                    + (int) ((System.currentTimeMillis() - millisAtStart) / 1000) + " sekunder efter start");
            if (lastMillis > 0) {
                System.out.println("Senaste tweetet skickades fr "
                        + (int) ((System.currentTimeMillis() - lastMillis) / 1000) + " sekunder sen");
            }
            lastMillis = System.currentTimeMillis();
            System.err.println("");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // FIXME Auto-generated catch block
                e.printStackTrace();
            }
        }
    } catch (Exception e) {
        driver.close();
        twitterSpam();
    }
    driver.close();
}

From source file:GlennsPack.GlennWebAPI.Example.java

License:Open Source License

public static void testGoogleSearch() {
    // Optional, if not specified, WebDriver will search your path for chromedriver.
    System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe");

    WebDriver driver = new ChromeDriver();
    driver.get("http://whatismybrowser.com");
    try {//from w w w . j av a  2 s.c  o m
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // FIXME Auto-generated catch block
        e.printStackTrace();
    } // Let the user actually see something!
    WebElement searchBox = driver.findElement(By.name("q"));
    searchBox.sendKeys("ChromeDriver");
    searchBox.submit();
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // FIXME Auto-generated catch block
        e.printStackTrace();
    } // Let the user actually see something!
    driver.quit();
}

From source file:GlennsPack.GlennWebAPI.findTextInPage.java

License:Open Source License

public findTextInPage(ArrayList<String> lookFor) {
    System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe");
    WebDriver driver = new ChromeDriver();

    driver.manage().window().setSize(new Dimension(2000, 800));

    driver.get("http://gojb.ml/chat");

    try {/*  w  w w  .  j  av  a2s .co  m*/
        Thread.sleep(500);
    } catch (InterruptedException e1) {
        // FIXME Auto-generated catch block
        e1.printStackTrace();
    }
    driver.findElement(By.xpath("//*[@id=\"menu\"]/header/div[1]")).click();
    driver.findElement(By.id("knapp")).click();
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        // FIXME Auto-generated catch block
        e.printStackTrace();
    }
    driver.switchTo().alert().sendKeys("GoJbBot");
    driver.switchTo().alert().accept();
    driver.findElement(By.id("knapp2")).click();

    while (found != true) {
        try {
            for (int index = 0; index < lookFor.size(); index++) {
                List<WebElement> element = driver
                        .findElements(By.xpath("//*[contains(translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ',"
                                + "'abcdefghijklmnopqrstuvwxyz'),\"" + lookFor.get(index).toLowerCase()
                                + "\")]"));

                for (int i = 0; i < element.size(); i++) {

                    if (!mathingsFound.contains(element.get(i).getText())) {
                        mathingsFound.add(element.get(i).getText());
                        System.out.println("FOUND!");
                        Found(lookFor.get(index).toLowerCase(), element.get(i).getText(), driver);
                    } else {
                        missmatch++;
                        if ((missmatch * lookFor.size()) == element.size()) {
                            System.out.println("OR ELSE");
                            throw new Exception();
                        }
                    }
                }
            }
        } catch (Exception e2) {
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // FIXME Auto-generated catch block
            e.printStackTrace();
        }
    }

}

From source file:GlennsPack.GlennWebAPI.Keybr.java

License:Open Source License

public Keybr() {
    //        System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe");
    //        System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe");

    ProfilesIni profileObj = new ProfilesIni();
    FirefoxProfile yourFFProfile = profileObj.getProfile("Glenn");

    WebDriver driver;

    driver = new FirefoxDriver(yourFFProfile);
    driver.get("https://www.keybr.com/practice");

    try {/*from  w ww.  j a  v  a  2s . com*/
        Thread.sleep(1000);
    } catch (Exception e) {
        e.printStackTrace();
    }

    Scanner reader = new Scanner(System.in); // Reading from System.in
    System.out.println("Enter a number: ");
    int n = reader.nextInt();

    runer(driver);
}

From source file:GlennsPack.GlennWebAPI.TwitchBot.java

License:Open Source License

public TwitchBot(ArrayList<String> lookFor) {
    System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe");
    WebDriver driver = new ChromeDriver();

    driver.manage().window().setSize(new Dimension(2000, 800));

    driver.manage().deleteAllCookies();//from   www  .ja  v a2 s .c o m

    //      driver.get("http://twitch.tv/login");
    //
    //      driver.findElement(By.id("username")).sendKeys("kakansbot");
    //      driver.findElement(By.xpath("//*[@id=\"loginForm\"]/div[2]/input")).sendKeys("falcor1122");
    //      driver.findElement(By.xpath("//*[@id=\"loginForm\"]/div[3]/input")).click();
    //
    //      driver.get("http://www.twitch.tv/kakan9898/chat");

    driver.get("https://api.twitch.tv/kraken/oauth2/authorize"
            + "?response_type=token&client_id=ic1pa8ll9hazkssp35klwsmpelqejqj&redirect_uri=http://twitch.tv/kakan9898/chat&scope=chat_login");
    try {
        driver.findElement(By.xpath("//*[@id=\"header_login\"]/span")).click();
    } catch (Exception e) {
        // FIXME: handle exception
    }

    driver.findElement(By.xpath("//*[@id=\"login\"]")).sendKeys("kakansbot");
    driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys("--");
    driver.findElement(By.xpath("//*[@id=\"oauth_submit\"]")).click();
    try {
        driver.findElement(By.xpath("//span[contains(text(),'Authorize')]")).click();
    } catch (Exception e) {
        // FIXME: handle exception
    }

    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // FIXME Auto-generated catch block
        e.printStackTrace();
    }
    try {
        driver.findElement(By.xpath("//*[@id=\"noty_796318084299728000\"]/div/div[2]/svg")).click();
    } catch (Exception e) {
        // FIXME: handle exception
    }
    driver.findElement(By.id("ember673")).sendKeys("I am now monotoring this chat! Be aware!", Keys.ENTER);

    while (found != true) {
        try {
            for (int index = 0; index < lookFor.size(); index++) {
                List<WebElement> element = driver.findElements(
                        By.xpath("//*[contains(translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ',\'" + abc
                                + "\'),\"" + lookFor.get(index).toLowerCase() + "\")]"));
                for (int i = 0; i < element.size(); i++) {
                    if (!(mathingsFound.contains(element.get(i)))) {
                        mathingsFound.add(element.get(i));
                        if (index < amounOfHello) {
                            sortOfText = "greet";
                            System.out.println(index + " <- index --- amountHello -> " + amounOfHello);
                        } else if (index >= amounOfHello && index < (amounOfHello + amountOfBye)) {
                            sortOfText = "bye";
                        } else {
                            sortOfText = "emoji";
                        }
                        System.out.println("FOUND " + lookFor.get(index) + "!");
                        System.err.println(element.get(i));
                        FoundString(lookFor.get(index).toLowerCase(), element.get(i).getText().toLowerCase(),
                                driver, sortOfText);
                    } else {
                        missmatch++;
                        if ((missmatch * lookFor.size()) == element.size()) {
                            System.out.println("OR ELSE");
                            throw new Exception();

                        }
                    }
                }
            }
            try {
                for (int i1 = 0; i1 < memesToLookFor.size(); i1++) {
                    List<WebElement> element = driver
                            .findElements(By.xpath("//img[@alt='" + memesToLookFor.get(i1) + "']"));
                    for (int i = 0; i < element.size(); i++) {
                        if (!(mathingsFound.contains(element.get(i)))) {
                            mathingsFound.add(element.get(i));
                            sortOfText = "meme";
                            FoundMeme(memesToLookFor.get(i1), driver);
                        }
                    }
                }
            } catch (Exception e) {
                // FIXME: handle exception
            }
        } catch (Exception e2) {
            e2.printStackTrace();
            System.out.println("Still running though");
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // FIXME Auto-generated catch block
            e.printStackTrace();
            System.out.println("Still running though");
        }
    }
}

From source file:google.TestGoogle.java

/**
 * @param args the command line arguments
 *///  w w w .  j  a va 2s  . co  m
public static void main(String[] args) throws InterruptedException {
    System.setProperty("webdriver.chrome.driver",
            "D:\\GitHub\\java\\Gradle\\SeleniumTest\\exe\\chromedriver.exe");

    WebDriver driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.get("http://bbs.sgcn.com/member.php?mod=logging&action=login");
    Thread.sleep(5000); // Let the user actually see something!
    //WebElement searchBox = driver.findElement(By.name("q"));
    //searchBox.sendKeys("ChromeDriver");
    //searchBox.submit();

    driver.findElement(By.id("u_u")).sendKeys("?");
    driver.findElement(By.id("u_p")).sendKeys("diesel");
    driver.findElement(By.className("u_s1")).submit();
    Thread.sleep(5000);
    driver.findElement(By.className("bind_skip")).submit();

    driver.get("http://bbs.sgcn.com/thread-15716879-1-1.html");
    JavascriptExecutor jse = (JavascriptExecutor) driver;
    WebElement we = driver.findElement(By.id("fastpostsubmit"));
    jse.executeScript("arguments[0].scrollIntoView(true);", we);
    driver.findElement(By.id("fastpostsubmit")).click();
    Thread.sleep(5000); // Let the user actually see something!
    driver.quit();
}

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

License:Apache License

public boolean shouldProcessURL(String URL) {
    System.out.print("============SELENIUM=================");
    System.out.println("DEBUG:::::" + URL);
    System.setProperty("webdriver.firefox.bin", "/Applications/Firefox.app/Contents/MacOS/firefox");
    WebDriver driver = new FirefoxDriver();

    // And now use this to visit Google
    driver.get(URL);
    try {/*from ww w .  j  a v a2 s. c  o m*/

        String url1, url2, url3, url4;

        url1 = "www.arguntrader.com/ucp.php?mode=login";
        url2 = "www.buyusedguns.net/login.php";
        url3 = "www.hawaiiguntrader.com/login/";
        url4 = "www.gunidaho.com/site/login.htm";

        WebElement username;
        WebElement password;
        WebElement submit;

        if (URL.contains(url1)) {
            System.out.println(url1
                    + " :***************************login page***********************************************8");
            username = driver.findElement(By.id("username"));
            username.sendKeys("bhanuprasad");
            password = driver.findElement(By.id("password"));
            password.sendKeys("lasvegas");
            submit = driver.findElement(By.name("login"));
            submit.submit();
        } else if (URL.contains(url2)) {
            System.out.println(url2
                    + " :***************************login page***********************************************8");
            username = driver.findElement(By.id("username"));
            username.sendKeys("bhanuirprasadir");
            password = driver.findElement(By.id("password"));
            password.sendKeys("bhanu@prasad");
            submit = driver.findElement(By.id("submit"));
            submit.submit();
        }

        else if (URL.contains(url3)) {
            System.out.println(url3
                    + " :***************************login page***********************************************8");
            username = driver.findElement(By.id("login_username"));
            username.sendKeys("bhanuir.prasadir@gmail.com");
            password = driver.findElement(By.id("login_password"));
            password.sendKeys("bhanu@prasad");
            submit = driver.findElement(By.id("login"));
            submit.submit();
        }

        else if (URL.contains(url4)) {
            System.out.println(url4
                    + " :***************************login page***********************************************8");
            username = driver.findElement(By.id("User_email"));
            username.sendKeys("bhanuir.prasadir@gmail.com");
            password = driver.findElement(By.id("User_password"));
            password.sendKeys("vcytaybmabzk");
            submit = driver.findElement(By.name("btnLogin"));
            submit.submit();
        } else if (URL.contains("page")) {
            System.out.println(URL
                    + " :************************pagination page***********************************************8");
            if (URL.contains("http://www.shooting.org/"))
                driver.findElement(By.xpath("//a[@rel='next']"));
            else if (URL.contains("https://www.alphacatarmory.com/"))
                driver.findElement(By.className("next"));

            else if (URL.contains("http://www.budsgunshop.com/catalog/"))
                driver.findElement(By.xpath("//a[@class='pageResults' and  @title=' Next Page ']"));
        } else if ((URL.contains("www.store.kimberamerica.com/customer/account/login"))
                || (URL.contains("www.palmettostatearmory.com/index.php/customer/account/login/"))
                || (URL.contains("www.osagecountyguns.com/customer/account/login/"))
                || (URL.contains("www.sogknives.com/customer/account/login/"))
                || (URL.contains("www.budsgunshop.com/catalog/login.php"))) {
            System.out.println(
                    "***************************login page***********************************************8");
            WebElement email_element = driver.findElement(By.id("email"));
            email_element.sendKeys("las567vegas@gmail.com");
            WebElement pass_element = driver.findElement(By.id("pass"));
            pass_element.sendKeys("lasvegas");
            WebElement submit_element = driver.findElement(By.id("send2"));
            submit_element.submit();
        }

    } catch (Exception e) {
        driver.quit();
        System.out.println("In exception!!!" + e);

    }
    return true;
}