Example usage for org.openqa.selenium WebDriver manage

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

Introduction

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

Prototype

Options manage();

Source Link

Document

Gets the Option interface

Usage

From source file:functional.testing.customerclient.page.LoginPage.java

public LoginPage(WebDriver driver) {
    this.driver = driver;
    driver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS);
    if (!"Customer Login".equals(driver.getTitle())) {
        throw new IllegalStateException("Not on login page.");
    }/* w  w w .  j  a  v a 2 s  .com*/
}

From source file:gheckodrivertest.BestJobsFirstPage.java

public static void main(String[] args) // TODO code application logic here
{
    try {/*from w ww  . j  a  va2s . c  om*/
        //System.setProperty("webdriver.gecko.driver", "D:\\Documentatie\\Selenium\\geckodriver\\geckodriver.exe");
        System.setProperty("webdriver.gecko.driver", "D:\\gdrwrapper.bat");
        System.setProperty("webdriver.gecko.logfile", "D:\\geckodriver.log");
        WebDriver driver = new FirefoxDriver();

        DesiredCapabilities capabilities = DesiredCapabilities.firefox();

        LoggingPreferences logPrefs = new LoggingPreferences();
        logPrefs.enable(LogType.BROWSER, Level.ALL);
        logPrefs.enable(LogType.CLIENT, Level.ALL);
        logPrefs.enable(LogType.DRIVER, Level.ALL);
        logPrefs.enable(LogType.SERVER, Level.ALL);
        logPrefs.enable(LogType.PERFORMANCE, Level.ALL);

        capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

        driver.get("http:\\bestjobs.eu");

        WebElement btnEnter = driver.findElement(By.xpath("html/body/div[1]/div/div/div/div/div[2]/a/button"));
        btnEnter.click();
        //driver.manage().timeouts().wait(30);
        System.out.println(driver.getTitle());
        /**
         * <li
         * class="sign-up-switch amplitude" data - key = "sign_up_email_started"
         * > <a
         * href = "/en/register" > Register <  / a
         * > < / li
         * >
         */
        // WebElement liSignIn = driver.findElement(By.className("sign-up-switch amplitude"));
        By btnRegister = By.linkText("Register");
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.presenceOfElementLocated(btnRegister));

        WebElement anchSignIn = driver.findElement(By.linkText("Register"));
        anchSignIn.click();
        //driver.manage().timeouts().wait(30);
        Logs logs = driver.manage().logs();
        LogEntries logEntries = logs.get(LogType.BROWSER);

        for (LogEntry logEntry : logEntries) {
            System.out.println("browser entry: " + logEntry.getMessage());
        }

        //driver.quit();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

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
    //      }//from   w ww .j  a v  a2  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 {//from   www  . j  a  va2 s  . c  om
        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 {//ww 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.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 ww.  ja  va2s. c  o  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.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   w  w w .  jav a2  s  . c  om*/

    //      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
 *//*from  w  w w . ja  v  a 2 s. 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.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 {//from   w w w  . ja  va2s .c o 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);
}

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

License:Apache License

public void processDriver(WebDriver driver) {

    //Handler for Login
    System.out.println(driver.getCurrentUrl());

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

    if (driver.getCurrentUrl().equals("http://www.academy.com/")) {
        System.out.println("team 6- http://www.academy.com");

        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

        driver.findElement(By.id("level-six")).click();

        WebElement emailButton = driver.findElement(By.id("WC_AccountDisplay_FormInput_logonId_In_Logon_1"));
        emailButton.clear();/*from ww w.  j  a  va2 s  .  c  om*/
        emailButton.sendKeys("shrutimundra.20@gmail.com");

        WebElement passButton = driver
                .findElement(By.id("WC_AccountDisplay_FormInput_logonPassword_In_Logon_1"));
        passButton.clear();
        passButton.sendKeys("sgpsteam6\n");

    } else if (driver.getCurrentUrl().equals("http://www.arguntrader.com/")) {
        WebElement emailButton = driver.findElement(By.id("username"));

        emailButton.clear();

        emailButton.sendKeys("team6ir4");

        WebElement passButton = driver.findElement(By.id("password"));

        passButton.clear();

        passButton.sendKeys("sgpsteam6\n");

    } else if (driver.getCurrentUrl().equals("http://www.armslist.com/")) {
        WebElement loginButton = driver.findElement(By.linkText("Login"));

        loginButton.click();

        WebElement emailButton = driver.findElement(By.id("email"));

        emailButton.clear();

        emailButton.sendKeys("shrutimundra.20@gmail.com");

        WebElement passButton = driver.findElement(By.id("password"));

        passButton.clear();

        passButton.sendKeys("sgpsteam6\n");

    } else if (driver.getCurrentUrl().equals("http://www.buyusedguns.net/")) {
        WebElement loginButton = driver.findElement(By.linkText("Login"));

        loginButton.click();

        WebElement emailButton = driver.findElement(By.name("username"));

        emailButton.clear();

        emailButton.sendKeys("irteam6");

        WebElement passButton = driver.findElement(By.name("password"));

        passButton.clear();

        passButton.sendKeys("sgpsteam6\n");

    } else if (driver.getCurrentUrl().equals("http://www.cheaperthandirt.com/")) {

        WebElement loginButton = driver.findElement(By.linkText("Sign In"));

        loginButton.click();

        WebElement emailButton = driver.findElement(By.id("ctl00_ContentPlaceHolderTopLevel_txtEmail"));

        emailButton.clear();

        emailButton.sendKeys("team6ir@gmail.com");

        WebElement passButton = driver.findElement(By.id("ctl00_ContentPlaceHolderTopLevel_txtPassword"));

        passButton.clear();

        passButton.sendKeys("sgpsteam6\n");

    } else if (driver.getCurrentUrl().equals("http://www.freeclassifieds.com/")) {

        WebElement loginButton = driver.findElement(By.id("Button1"));

        loginButton.click();

        WebElement emailButton = driver.findElement(By.id("phMain_txtEmail"));

        emailButton.clear();

        emailButton.sendKeys("team6ir@gmail.com");

        WebElement passButton = driver.findElement(By.id("phMain_txtPassword"));

        passButton.clear();

        passButton.sendKeys("sgpsteam6\n");

    } else if (driver.getCurrentUrl().equals("http://freegunclassifieds.com/")) {

        WebElement loginButton = driver.findElement(By.id("login_open"));

        loginButton.click();

        WebElement emailButton = driver.findElement(By.id("email"));

        emailButton.clear();

        emailButton.sendKeys("team6ir@gmail.com");

        WebElement passButton = driver.findElement(By.id("password"));

        passButton.clear();

        passButton.sendKeys("sgpsteam6\n");

    } else if (driver.getCurrentUrl().equals("http://www.gandermountain.com/")) {

        WebElement loginButton = driver.findElement(By.xpath("//*[@class = 'top-level']"));
        loginButton.click();

        WebElement emailButton = driver.findElement(By.id("header-login-email"));

        emailButton.clear();

        emailButton.sendKeys("team6ir@gmail.com");

        WebElement passButton = driver.findElement(By.name("password"));

        passButton.clear();

        passButton.sendKeys("sgpsteam6\n");

    } else if (driver.getCurrentUrl().equals("http://www.gunauction.com/")) {

        //gunauction.com

        WebElement loginButton = driver.findElement(By.className("login-window"));

        loginButton.click();

        WebElement emailButton = driver.findElement(By.name("EMail"));

        emailButton.clear();

        emailButton.sendKeys("team6ir@gmail.com");

        WebElement passButton = driver.findElement(By.name("Password1"));

        passButton.clear();

        passButton.sendKeys("sgpsteam6\n");

    } else if (driver.getCurrentUrl().equals("http://www.gunlistings.org/")) {

        //gunlistings.org

        WebElement loginButton = driver.findElement(By.linkText("Login"));

        loginButton.click();

        WebElement emailButton = driver.findElement(By.name("email_login"));

        emailButton.clear();

        emailButton.sendKeys("team6ir@gmail.com");

        WebElement passButton = driver.findElement(By.name("password"));

        passButton.clear();

        passButton.sendKeys("sgpsteam6\n");

    }
}