List of usage examples for org.openqa.selenium WebDriver getPageSource
String getPageSource();
From source file:edu.samplu.common.WebDriverUtil.java
License:Educational Community License
/*** * @link ITUtil#checkForIncidentReport//w ww . j a va 2 s. c o m * @param driver * @param locator * @param message */ public static void checkForIncidentReport(WebDriver driver, String locator, Failable failable, String message) { ITUtil.checkForIncidentReport(driver.getPageSource(), locator, failable, message); }
From source file:edu.samplu.common.WebDriverUtil.java
License:Educational Community License
/** * Logs in using the KRAD Login Page// w w w. ja v a 2 s. co m * If the JVM arg remote.autologin is set, auto login as admin will not be done. * @param driver * @param userName * @param failable * @throws InterruptedException */ public static void kradLogin(WebDriver driver, String userName, Failable failable) throws InterruptedException { driver.findElement(By.name("login_user")).clear(); driver.findElement(By.name("login_user")).sendKeys(userName); driver.findElement(By.id("Rice-LoginButton")).click(); Thread.sleep(1000); String contents = driver.getPageSource(); ITUtil.failOnInvalidUserName(userName, contents, failable); ITUtil.checkForIncidentReport(driver.getPageSource(), "Krad Login", failable, "Krad Login failure"); }
From source file:edu.samplu.common.WebDriverUtil.java
License:Educational Community License
/** * Logs into the Rice portal using the KNS Style Login Page. * @param driver//from w w w . j a v a 2 s. co m * @param userName * @param failable * @throws InterruptedException */ public static void login(WebDriver driver, String userName, Failable failable) throws InterruptedException { driver.findElement(By.name("__login_user")).clear(); driver.findElement(By.name("__login_user")).sendKeys(userName); driver.findElement(By.cssSelector("input[type=\"submit\"]")).click(); Thread.sleep(1000); String contents = driver.getPageSource(); ITUtil.failOnInvalidUserName(userName, contents, failable); ITUtil.checkForIncidentReport(driver.getPageSource(), "KNS Login", failable, "KNS Login failure"); }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_10.</p> */// w w w.j a v a 2s . c o m public static void browserEngineTest_10() { FirefoxProfile profile = new FirefoxProfile( TestUtils.getWebdriverProfile("/home/cjneasbi/.mozilla/firefox", "webdriver")); WebDriver wdriver = new FirefoxDriver(null, profile); wdriver.get("http://www.dkfjaojfko.com"); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(wdriver.getCurrentUrl()); System.out.println(wdriver.getTitle()); System.out.println(wdriver.getPageSource()); wdriver.quit(); }
From source file:edu.usc.cs.ir.htmlunit.handler.Arguntrader.java
License:Apache License
public String processDriver(final WebDriver driver) { boolean check = false; try {//w w w .ja v a 2s. c o m WebElement e = driver.findElement(By.id("username")); check = true; } catch (Exception e) { System.out.println("No Login Form detected"); } if (check) { WebElement username = driver.findElement(By.id("username")); WebElement password = driver.findElement(By.id("password")); username.sendKeys("username"); password.sendKeys("password"); driver.findElement(By.className("button1")).click(); (new WebDriverWait(driver, 8)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } return d.getCurrentUrl().toLowerCase().contains(driver.getCurrentUrl().toLowerCase()); } }); } return driver.getPageSource().replaceAll("&", "&"); }
From source file:edu.usc.cs.ir.htmlunit.handler.HtmlUnitWebDriver.java
License:Apache License
public static String getHTMLContent(WebDriver driver) { try {/*from ww w. j a va2s.c o m*/ String innerHtml = ""; if (enableJavascript) { WebElement body = driver.findElement(By.tagName("body")); innerHtml = (String) ((JavascriptExecutor) driver).executeScript("return arguments[0].innerHTML;", body); } else innerHtml = driver.getPageSource().replaceAll("&", "&"); return innerHtml; } catch (Exception e) { TemporaryFilesystem.getDefaultTmpFS().deleteTemporaryFiles(); cleanUpDriver(driver); throw new RuntimeException(e); } }
From source file:edu.usc.cs.ir.htmlunit.handler.JncManu.java
License:Apache License
public String processDriver(final WebDriver driver) { return driver.getPageSource().replaceAll("&", "&"); }
From source file:edu.usc.cs.ir.selenium.handler.Arguntrader.java
License:Apache License
public String processDriver(final WebDriver driver) { boolean check = false; try {/*from w w w . j av a 2 s. co m*/ WebElement e = driver.findElement(By.id("username")); check = true; } catch (Exception e) { System.out.println("No Login Form detected"); } if (check) { WebElement username = driver.findElement(By.id("username")); WebElement password = driver.findElement(By.id("password")); username.sendKeys("username"); password.sendKeys("password"); driver.findElement(By.className("button1")).click(); (new WebDriverWait(driver, 8)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } return d.getCurrentUrl().toLowerCase().contains(driver.getCurrentUrl().toLowerCase()); } }); } //System.out.println(); return driver.getPageSource().replaceAll("&", "&"); }
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();//from w w w.j ava 2s. 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:fll.web.IntegrationTestUtils.java
License:Open Source License
/** * Store screenshot and other information for debugging the error. * //from w w w. jav a 2s . c o m * @param filePrefix prefix for the files that are created * @param driver * @throws IOException */ public static void storeScreenshot(final String filePrefix, final WebDriver driver) throws IOException { final Path tempDir = Files.createTempDirectory(Paths.get("screenshots"), filePrefix); if (driver instanceof TakesScreenshot) { final Path screenshot = tempDir.resolve("screenshot.png"); final File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); Files.copy(scrFile.toPath(), screenshot); LOGGER.info("Screenshot saved to " + screenshot.toAbsolutePath().toString()); } else { LOGGER.warn("Unable to get screenshot"); } final Path htmlFile = tempDir.resolve("page.html"); final String html = driver.getPageSource(); final BufferedWriter writer = Files.newBufferedWriter(htmlFile); writer.write(html); writer.close(); LOGGER.info("HTML saved to " + htmlFile.toAbsolutePath().toString()); // get the database final Path dbroot = Paths.get("tomcat", "webapps", "fll-sw", "WEB-INF"); LOGGER.info("Copying database files from " + dbroot.toAbsolutePath() + " to " + tempDir.toAbsolutePath()); try (final DirectoryStream<Path> stream = Files.newDirectoryStream(dbroot, "flldb*")) { for (final Path entry : stream) { if (Files.isRegularFile(entry)) { Files.copy(entry, tempDir.resolve(dbroot.relativize(entry))); LOGGER.info("Copied database file " + entry.toString()); } } } catch (final DirectoryIteratorException ex) { LOGGER.error("Unable to get database files", ex); } LOGGER.info("Finished copying database files"); }