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:es.udc.tfg_es.clubtriatlon.test.web.RoleWebTest.java

License:Open Source License

@Test
public void testCheckNoAuthz() {

    WebDriver driver = SeleniumMethods.auntenticateUser();
    //Can't see "Administrador" menu because no has his role, must go with url
    driver.get("http://localhost:9090/triatlon/admin/plannings/PlanningWeekly");
    //Can see the unauthorized message and the "Ir a inicio" link
    assertNotNull(driver.findElement(By.id("indexPage")));
    assertEquals(driver.findElement(By.id("indexPage")).getText(), "Ir a inicio");

}

From source file:facebook.Autenticate.java

License:Open Source License

public static void perform(WebDriver driver, String email, String password) {
    driver.get(Globals.START_PAGE);
    WebElement email_element = driver.findElement(By.xpath("//*[@id='email']"));
    email_element.sendKeys(email);//  w  ww. j a  v  a 2  s  . com
    WebElement password_element = driver.findElement(By.xpath("//*[@id='pass']"));
    password_element.sendKeys(password);
    WebElement click_element = driver.findElement(By.xpath("//*[@type='submit']"));
    click_element.click();
    return;
}

From source file:FacebookRequest.Facebook.java

public FacebookAccount login(String u, String p) throws IOException {
    FacebookAccount myFacebook = new FacebookAccount();
    WebDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME, true);
    driver.get("https://m.facebook.com/");
    driver.findElement(By.name("email")).sendKeys(u);
    driver.findElement(By.name("pass")).sendKeys(p);
    driver.findElement(By.name("login")).click();
    String HTMLSource = driver.getPageSource();
    Set<Cookie> cookies = driver.manage().getCookies();
    driver.close();//  ww w .jav  a2  s .  c om

    Document doc = Jsoup.parse(HTMLSource);
    Elements doc_inputs = doc.select("input[name=fb_dtsg]");
    Pattern DTSG_Pattern = Pattern.compile("(\\w{12}\\:\\w{12})");
    if (doc_inputs.isEmpty())
        return null;
    String DTSG = doc_inputs.first().attr("value");
    if (!DTSG_Pattern.matcher(DTSG).find())
        return null;
    myFacebook.setDTSH(DTSG);

    String myCookie = "";
    for (Cookie cookie : cookies)
        myCookie = myCookie + cookie.getName() + "=" + cookie.getValue() + "; ";
    myFacebook.setCookie(myCookie);

    //System.out.println(myFacebook.getCookie()+"\n"+myFacebook.getDTSH());
    return myFacebook;
}

From source file:fbapi.FBAPI.java

/**
 * @param args the command line arguments
 *///ww w .j a  v  a2  s  . co  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:fll.web.IntegrationTestUtils.java

License:Open Source License

/**
 * Load a page and check to make sure the page didn't crash.
 * /*w  w w.ja va2 s .  c o  m*/
 * @param selenium the test controller
 * @param url the page to load
 * @throws IOException
 * @throws InterruptedException 
 */
public static void loadPage(final WebDriver selenium, final String url)
        throws IOException, InterruptedException {
    selenium.get(url);

    Thread.sleep(WAIT_FOR_PAGE_LOAD_MS);

    assertNoException(selenium);
}

From source file:fll.web.IntegrationTestUtils.java

License:Open Source License

/**
 * Initialize the database using the given challenge descriptor.
 * /*from   w  ww.  j av  a  2  s.  c om*/
 * @param driver the test controller
 * @param challengeFile a file to read the challenge description from. This
 *          file will not be deleted.
 * @throws InterruptedException 
 * @throws IOException
 */
public static void initializeDatabase(final WebDriver driver, final Path challengeFile)
        throws InterruptedException {

    driver.get(TestUtils.URL_ROOT + "setup/");
    Thread.sleep(WAIT_FOR_PAGE_LOAD_MS);

    if (isElementPresent(driver, By.name("submit_login"))) {
        login(driver);

        driver.get(TestUtils.URL_ROOT + "setup/");
        Thread.sleep(WAIT_FOR_PAGE_LOAD_MS);
    }

    final WebElement fileEle = driver.findElement(By.name("xmldocument"));
    fileEle.sendKeys(challengeFile.toAbsolutePath().toString());

    final WebElement reinitDB = driver.findElement(By.name("reinitializeDatabase"));
    reinitDB.click();

    Thread.sleep(WAIT_FOR_PAGE_LOAD_MS);

    try {
        final Alert confirmCreateDB = driver.switchTo().alert();
        LOGGER.info("Confirmation text: " + confirmCreateDB.getText());
        confirmCreateDB.accept();
    } catch (final NoAlertPresentException e) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("No alert found, assuming the database was empty and didn't need an alert.");
        }
    }

    Thread.sleep(2 * WAIT_FOR_PAGE_LOAD_MS);

    driver.findElement(By.id("success"));

    // setup user
    final WebElement userElement = driver.findElement(By.name("user"));
    userElement.sendKeys(TEST_USERNAME);

    final WebElement passElement = driver.findElement(By.name("pass"));
    passElement.sendKeys(TEST_PASSWORD);

    final WebElement passCheckElement = driver.findElement(By.name("pass_check"));
    passCheckElement.sendKeys(TEST_PASSWORD);

    final WebElement submitElement = driver.findElement(By.name("submit_create_user"));
    submitElement.click();
    Thread.sleep(2 * WAIT_FOR_PAGE_LOAD_MS);

    driver.findElement(By.id("success-create-user"));

    login(driver);

}

From source file:fll.web.IntegrationTestUtils.java

License:Open Source License

/**
 * Initialize a database from a zip file.
 * /*from   www  . j  a v a2s . com*/
 * @param selenium the test controller
 * @param inputStream input stream that has database to load in it, this input
 *          stream is closed by this method upon successful completion
 * @throws IOException
 * @throws InterruptedException 
 */
public static void initializeDatabaseFromDump(final WebDriver selenium, final InputStream inputStream)
        throws IOException, InterruptedException {
    Assert.assertNotNull(inputStream);
    final File dumpFile = IntegrationTestUtils.storeInputStreamToFile(inputStream);
    try {
        selenium.get(TestUtils.URL_ROOT + "setup/");

        if (isElementPresent(selenium, By.name("submit_login"))) {
            login(selenium);

            selenium.get(TestUtils.URL_ROOT + "setup/");
        }

        final WebElement dbEle = selenium.findElement(By.name("dbdump"));
        dbEle.sendKeys(dumpFile.getAbsolutePath());

        final WebElement createEle = selenium.findElement(By.name("createdb"));
        createEle.click();

        try {
            final Alert confirmCreateDB = selenium.switchTo().alert();
            LOGGER.info("Confirmation text: " + confirmCreateDB.getText());
            confirmCreateDB.accept();
        } catch (final NoAlertPresentException e) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("No alert found, assuming the database was empty and didn't need an alert.");
            }
        }

        selenium.findElement(By.id("success"));

        // setup user
        final WebElement userElement = selenium.findElement(By.name("user"));
        userElement.sendKeys(TEST_USERNAME);

        final WebElement passElement = selenium.findElement(By.name("pass"));
        passElement.sendKeys(TEST_PASSWORD);

        final WebElement passCheckElement = selenium.findElement(By.name("pass_check"));
        passCheckElement.sendKeys(TEST_PASSWORD);

        final WebElement submitElement = selenium.findElement(By.name("submit_create_user"));
        submitElement.click();

        selenium.findElement(By.id("success-create-user"));

        login(selenium);
    } finally {
        if (!dumpFile.delete()) {
            dumpFile.deleteOnExit();
        }
    }
    login(selenium);
}

From source file:fll.web.IntegrationTestUtils.java

License:Open Source License

/**
 * Login to fll//from w  w w  .  ja  v a  2  s .c om
 * @throws InterruptedException 
 */
public static void login(final WebDriver driver) throws InterruptedException {
    driver.get(TestUtils.URL_ROOT + "login.jsp");

    final WebElement userElement = driver.findElement(By.name("user"));
    userElement.sendKeys(TEST_USERNAME);

    final WebElement passElement = driver.findElement(By.name("pass"));
    passElement.sendKeys(TEST_PASSWORD);

    final WebElement submitElement = driver.findElement(By.name("submit_login"));
    submitElement.click();
    Thread.sleep(WAIT_FOR_PAGE_LOAD_MS);

}

From source file:gh.funthomas424242.webapp.books.web.pages.SeleniumPage.java

License:Open Source License

public SeleniumPage open(final WebDriver driver) {
    final String pageUrl = getPageUrl();
    driver.get(pageUrl);
    return this;
}

From source file:gheckodrivertest.BestJobsFirstPage.java

public static void main(String[] args) // TODO code application logic here
{
    try {//w  w w.ja v a  2  s  .  c  o  m
        //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();
    }
}