List of usage examples for org.openqa.selenium WebDriver getPageSource
String getPageSource();
From source file:WebDriverEventHandler.java
License:Open Source License
/** * Called after {@link org.openqa.selenium.WebElement#click WebElement.click()}. Not called, if an exception is * thrown./*from ww w. jav a 2 s . com*/ * * @param element * @param driver */ @Override public void afterClickOn(WebElement element, WebDriver driver) { System.out.println("afterClickOn fired !!" ) ; System.out.println(element.getTagName()) ; System.out.println(driver.getPageSource()) ; }
From source file:WebDriverEventHandler.java
License:Open Source License
/** * Called before {@link org.openqa.selenium.WebElement#clear WebElement.clear()}, {@link org.openqa.selenium.WebElement#sendKeys * WebElement.sendKeys(...)}.//from w w w . ja va2 s. c o m * * @param element * @param driver */ @Override public void beforeChangeValueOf(WebElement element, WebDriver driver) { System.out.println("beforeChangeValueOf fired !!" ) ; System.out.println(element.getTagName()) ; System.out.println(driver.getPageSource()) ; }
From source file:WebDriverEventHandler.java
License:Open Source License
/** * Called after {@link org.openqa.selenium.WebElement#clear WebElement.clear()}, {@link org.openqa.selenium.WebElement#sendKeys * WebElement.sendKeys(...)}}. Not called, if an exception is thrown. * * @param element/*from w ww. ja va 2 s . c o m*/ * @param driver */ @Override public void afterChangeValueOf(WebElement element, WebDriver driver) { System.out.println("afterChangeValueOf fired !!" ) ; System.out.println(element.getTagName()) ; System.out.println(driver.getPageSource()) ; }
From source file:WebDriverEventHandler.java
License:Open Source License
/** * Called before {@link org.openqa.selenium.remote.RemoteWebDriver#executeScript(String, Object[]) } * * @param script//from www. ja v a2 s . c om * @param driver */ @Override public void beforeScript(String script, WebDriver driver) { System.out.println("beforeScript fired !!" ) ; System.out.println(script) ; System.out.println(driver.getPageSource()) ; }
From source file:WebDriverEventHandler.java
License:Open Source License
/** * Called after {@link org.openqa.selenium.remote.RemoteWebDriver#executeScript(String, Object[]) }. Not called if an exception is thrown * * @param script// w w w .ja v a 2s.c om * @param driver */ @Override public void afterScript(String script, WebDriver driver) { System.out.println("afterScript fired !!" ) ; System.out.println(script) ; System.out.println(driver.getPageSource()) ; }
From source file:WebDriverEventHandler.java
License:Open Source License
/** * Called whenever an exception would be thrown. * * @param throwable// w w w . j a v a2s . c o m * @param driver */ @Override public void onException(Throwable throwable, WebDriver driver) { System.out.println("onException fired !!" ) ; System.out.println(throwable.getMessage()) ; System.out.println(driver.getPageSource()) ; }
From source file:TestWriteanArticle.java
@org.junit.Test public void positive() throws InterruptedException { System.setProperty("webdriver.gecko.driver", "C://Users/Mari/Downloads/geckodriver.exe"); WebDriver webDriver = new FirefoxDriver(); String page = "http://www.wikihow.com/Special:CreatePage"; webDriver.get(page);/*from ww w . j a v a2 s . c o m*/ WebElement title = webDriver.findElement(By.id("cp_title_input")); title.sendKeys("how to use selenium"); webDriver.findElement(By.id("cp_title_btn")).click(); Thread.sleep(10); WebDriverWait wait = new WebDriverWait(webDriver, 50); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("cpr_title_hdr"))); assertTrue(webDriver.getPageSource().contains("Are any of these topics the same as yours?")); webDriver.close(); }
From source file:TestWriteanArticle.java
@org.junit.Test public void negative() throws InterruptedException { System.setProperty("webdriver.gecko.driver", "C://Users/Mari/Downloads/geckodriver.exe"); WebDriver webDriver = new FirefoxDriver(); String page = "http://www.wikihow.com/Special:CreatePage"; webDriver.get(page);//from w ww . j a v a 2 s .co m WebElement title = webDriver.findElement(By.id("cp_title_input")); title.sendKeys("how to use wikiHow"); webDriver.findElement(By.id("cp_title_btn")).click(); Thread.sleep(10); WebDriverWait wait = new WebDriverWait(webDriver, 50); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("cpr_title_hdr"))); assertTrue(webDriver.getPageSource().contains("That article already exists!")); webDriver.close(); }
From source file:alwaysonline.Access.java
License:Open Source License
/** * Method for the access./*ww w . j a va 2 s . com*/ * @param user String that contains the username * @param pass String that contains the password * @return Access result: 0 failed, 1 success. */ public int doAccess(String user, String pass) { WebDriver driver = new HtmlUnitDriver(); WebElement username, password; // access page driver.get("https://auth3.unipi.it/auth/perfigo_cm_validate.jsp"); // looking for the credential fields username = driver.findElement(By.name("username")); username.clear(); username.sendKeys(user); password = driver.findElement(By.name("password")); password.clear(); password.sendKeys(pass); // Executing the access, submiting values driver.findElement(By.name("username")).submit(); // If the session was already opened if (driver.getPageSource().contains("Too many users using this account")) { // put again credentials username = driver.findElement(By.name("username")); username.clear(); username.sendKeys(user); password = driver.findElement(By.name("password")); password.clear(); password.sendKeys(pass); // remove the old session driver.findElement(By.name("remove_old")).click(); // submit again access data driver.findElement(By.name("username")).submit(); } // controll if the access has been done successful if (driver.getPageSource().contains("You have been successfully logged on the network")) return 1; return 0; }
From source file:at.ac.tuwien.big.testsuite.impl.selenium.BaseSeleniumTest.java
License:Apache License
protected void exportCurrentHTML(WebDriver driver, String filename) { File exportFile = new File(groupDir, BASE_EXPORT_DIR + filename); File parent = exportFile.getParentFile(); if (!parent.exists()) { parent.mkdirs();//from w w w . j av a2 s .c om } PrintWriter out = null; try { exportFile.createNewFile(); String pageSource = driver.getPageSource(); Document doc = DomUtils.createDocument(new ByteArrayInputStream(pageSource.getBytes("UTF-8"))); String encoding = "UTF-8"; boolean encodingFound = false; // Try to find the correct encoding List<Element> metaTags = DomUtils.listByXpath(doc.getDocumentElement(), "//meta[@http-equiv=\"content-type\"]"); for (Element meta : metaTags) { String attContent = meta.getAttribute("content").trim(); if (!attContent.isEmpty()) { String[] parts = attContent.split(";"); for (String part : parts) { if (part.trim().startsWith("charset=")) { encoding = part.split("=")[1]; encodingFound = true; break; } } if (encodingFound) { break; } } } if (LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "Detected encoding: {0}", encoding); } out = new PrintWriter(exportFile, encoding); out.print(pageSource); out.flush(); } catch (FileNotFoundException ex) { LOG.log(Level.SEVERE, null, ex); } catch (IOException ex) { LOG.log(Level.SEVERE, null, ex); } finally { if (out != null) { out.close(); } } }