List of usage examples for org.openqa.selenium WebDriver getPageSource
String getPageSource();
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
private void focusToCurrentWindow(WebDriver driver) { try {/*from www. java 2s . c om*/ JavascriptExecutor jsExecutor = (JavascriptExecutor) driver; if (driver.getPageSource().toLowerCase(Locale.getDefault()).contains("<html")) { jsExecutor.executeScript("window.focus();"); } } catch (Exception e) { getLog().error(e); } }
From source file:com.waku.mmdataextract.SalesIssues2.java
License:Open Source License
/** * @param args/* w w w. ja va2 s. c o m*/ * @throws Exception */ public static void main(String[] args) throws Exception { String formUrl = "http://shouji.gd.chinamobile.com/gdmobile/productDetail/operatorssalesHeaderAction.do"; String fromUrl2 = "http://shouji.gd.chinamobile.com/gdmobile/productDetail/operatorssalesHeaderAction.do?provinceID=1&cityID="; String baseUrl = "http://shouji.gd.chinamobile.com/gdmobile/productDetail/operatorssalesSearchAction.do?type=1&brandId=0&productId=0&provinceId=1"; WebDriver driver = new ChromeDriver(); // Get the citySet from form url System.out.println("Go to url => " + formUrl); driver.get(formUrl); WebElement citySelector = driver.findElement(By.id("cityID")); List<WebElement> cityOptions = citySelector.findElements(By.tagName("option")); Map<String, String> cityIdNameMap = new HashMap<String, String>(); for (WebElement cityOption : cityOptions) { cityIdNameMap.put(cityOption.getAttribute("value"), cityOption.getText()); } System.out.println("Find cities: \n" + cityIdNameMap); // A class to hold Sales issue id and name class SalesIssue { @Override public String toString() { return id + ":" + name; } public SalesIssue(String id, String name) { this.id = id; this.name = name; } String id; String name; } // Get sales issues info Map<String, Set<SalesIssue>> citySalesIssueMap = new HashMap<String, Set<SalesIssue>>(); for (String cityId : cityIdNameMap.keySet()) { String cityUrl = fromUrl2 + cityId; driver.get(cityUrl); System.out.println("Go to url => " + cityUrl); WebElement salesIssueSelector = driver.findElement(By.id("salesissue")); List<WebElement> salesIssueOptions = salesIssueSelector.findElements(By.tagName("option")); if (salesIssueOptions.get(0).getAttribute("value").equals("0")) { System.out.println("No sales issues for " + cityIdNameMap.get(cityId)); } else { Set<SalesIssue> salesIssueSet = new HashSet<SalesIssue>(); for (WebElement salesIssueOption : salesIssueOptions) { SalesIssue salesIssue = new SalesIssue(salesIssueOption.getAttribute("value"), salesIssueOption.getText()); salesIssueSet.add(salesIssue); } citySalesIssueMap.put(cityId, salesIssueSet); System.out.println("Find sales issues: \n" + citySalesIssueMap); } } for (String cityId : cityIdNameMap.keySet()) { for (SalesIssue salesIssue : citySalesIssueMap.get(cityId)) { String finalUrl = baseUrl + "&cityId=" + cityId + "&salesissue=" + salesIssue.id; driver.get(finalUrl); System.out.println("Go to url => " + finalUrl); System.out .println("Province,,City," + cityIdNameMap.get(cityId) + ",Sales," + salesIssue.name); System.out.println(driver.getPageSource()); } } }
From source file:Data.Database.java
public void addTeams() throws InterruptedException, FileNotFoundException { Scanner fileScanner = new Scanner(new File("login.txt")); String username = fileScanner.nextLine(); String password = fileScanner.nextLine(); WebDriver firefoxDriver = new FirefoxDriver(); //Open the url which we want in firefox firefoxDriver.get("http://www.fantrax.com/fantasy/teamRosterChart.go?leagueId=ntokropui8nbbjt1"); WebElement link;/* www . j a v a 2s . c o m*/ link = firefoxDriver.findElement(By.id("loginZone")); link.click(); WebElement input; input = firefoxDriver.findElement(By.id("j_username")); input.sendKeys(username); input = firefoxDriver.findElement(By.id("realPassword")); input.sendKeys(password); input.sendKeys(Keys.RETURN); Thread.sleep(2000); firefoxDriver.get("http://www.fantrax.com/fantasy/teamRosterChart.go?leagueId=ntokropui8nbbjt1"); String data = firefoxDriver.getPageSource(); data = data.substring(data.indexOf("<table class=\"fantTable rosterChart\">")); data = data.substring(0, data.indexOf("</tbody>")); String[] temp = data.split("<td class=\"team leftCol\">"); //System.out.println(temp[1]); for (int i = 1; i < temp.length; i++) { Team t = new Team(); t.fillTeam(years, lookup, temp[i]); fh_teams.add(t); t.getTotals(); t.printAverages(); } firefoxDriver.quit(); }
From source file:de.ppi.selenium.util.ScreenshotUtils.java
License:Apache License
/** * Save a screenshot.//from w w w. ja va 2 s. com * * @param screenshotFileName name of the file, without ending. * @param driver the webdriver. */ public static void saveScreenshot(String screenshotFileName, WebDriver driver) { try { WebDriver wrappedDriver = driver; while (wrappedDriver instanceof WrapsDriver) { wrappedDriver = ((WrapsDriver) wrappedDriver).getWrappedDriver(); } if (wrappedDriver instanceof TakesScreenshot) { final byte[] screenshot = ((TakesScreenshot) wrappedDriver).getScreenshotAs(OutputType.BYTES); FileUtils.writeByteArrayToFile(new File(screenshotFileName + ".png"), screenshot); } else if (wrappedDriver instanceof HtmlUnitDriver) { FileUtils.write(new File(screenshotFileName + ".html"), wrappedDriver.getPageSource(), "UTF-8"); } else { LOG.warn("The current driver doesn't make screenshots"); } } catch (IOException e) { LOG.error("IO-Error during creating of the screenshot ", e); } }
From source file:de.tudarmstadt.ukp.argumentation.data.roomfordebate.NYTimesCommentsScraper.java
License:Apache License
/** * Downloads the page and rolls out the entire discussion using {@link FirefoxDriver}. * * @param articleUrl url, e.g. {@code http://www.nytimes.com/roomfordebate/2015/02/04/regulate-internet-providers/the-internet-is-back-to-solid-regulatory-ground} * @return generated HTML code of the entire page * @throws InterruptedException//from www. j ava2 s . c o m */ public String readHTML(String articleUrl) throws InterruptedException { // load the url WebDriver driver = new FirefoxDriver(); driver.get(articleUrl); // roll-out the entire discussion // TODO fix that, is broken in actual versions of Selenium/Firefox /* List<WebElement> commentsExpandElements; do { commentsExpandElements = driver.findElements(By.cssSelector("div.comments-expand")); // click on each of them for (WebElement commentsExpandElement : commentsExpandElements) { // only if visible & enabled if (commentsExpandElement.isDisplayed() && commentsExpandElement.isEnabled()) { commentsExpandElement.click(); // give it some time to load new comments Thread.sleep(3000); } } } // until there is one remaining that doesn't do anything... while (commentsExpandElements.size() > 1); */ // get the html String result = driver.getPageSource(); // close firefox driver.close(); return result; }
From source file:dk.netarkivet.systemtest.functional.ExtendedFieldTest.java
License:Open Source License
public void extendedDomainStringFieldTest(WebDriver driver, String extendedIDForTest) throws Exception { addStep("Create a new String type field (name:" + extendedIDForTest + ") for domains", ""); PageHelper.gotoPage(PageHelper.MenuPages.ExtendedFields); driver.findElement(By.linkText("create Extended Field")).click(); // Todo needs more specific find driver.findElement(By.name("extf_name")).clear(); driver.findElement(By.name("extf_name")).sendKeys(extendedIDForTest); Select select = new Select(driver.findElement(By.name("extf_datatype"))); select.selectByVisibleText("String"); driver.findElement(By.cssSelector("input[type=\"submit\"]")).click(); addStep("Edit the default domain (" + HarvestUtils.DEFAULT_DOMAIN + ")", "The new extended field should be shown"); DomainWebTestHelper.editDomain(HarvestUtils.DEFAULT_DOMAIN); NASAssert.assertTrue(driver.getPageSource().contains(extendedIDForTest)); addStep("Fill out the new extended field with a value and save the " + "updated domain", ""); addStep("Reopen the domain", "The new extended field should contain the newly defined value"); }
From source file:dk.netarkivet.systemtest.performance.DatabaseMigrationSanityTest.java
License:Open Source License
/** * Basic sanity test that the current production database can be consistently upgraded with the latest NAS software. * This test is designed to be cheap to run so it can easily be tested on any snapshot. *//* w w w . j a va 2 s . c o m*/ @Test(groups = { "performancetest" }) public void dbMigrationSanityTest() throws Exception { WebDriver driver = new FirefoxDriver(); TestGUIController TestGUIController = new TestGUIController(testController); driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); String baseUrl = testController.ENV.getGuiHost() + ":" + testController.ENV.getGuiPort(); PageHelper.initialize(driver, baseUrl); TestGUIController.waitForGUIToStart(60); addFixture("Opening NAS front page."); PageHelper.gotoPage(PageHelper.MenuPages.AliasSummary.Frontpage); addStep("Ingest some domains", "The domains should be created."); DomainWebTestHelper.createDomain(new String[] { "netarkivet.dk", "kb.dk", "kaarefc.dk" }); WebElement element = null; try { element = driver.findElement(By.tagName("h4")); } catch (Exception e) { element = driver.findElement(By.id("message")); } NASAssert.assertTrue(element.getText().contains("These domains have now been created") || element.getText().contains("already exist")); addStep("Opening bitpreservation section of GUI.", "The page should open and show the number of files in the archive."); driver.findElement(By.linkText("Bitpreservation")).click(); driver.getPageSource().matches("Number of files:.*[0-9]{2}"); addStep("Create a selective harvest", "The harvest should be created successfully and be listed in the HD list"); String harvestId = "harvest_" + (new Date()).getTime(); SelectiveHarvestPageHelper.createSelectiveHarvest(harvestId, "a harvest", new String[] { "netarkivet.dk", "kb.dk" }); NASAssert.assertTrue(driver.getPageSource().contains(harvestId), harvestId + " not found in harvest list after creation"); }
From source file:edu.ncsu.csc.itrust.selenium.CreateHCPTest.java
public void testCreateValidHCP() throws Exception { WebDriver driver = login("9000000001", "pw"); assertLogged(TransactionType.HOME_VIEW, 9000000001L, 0L, ""); assertEquals("iTrust - Admin Home", driver.getTitle()); driver.findElement(By.linkText("Add HCP")).click(); assertEquals("iTrust - Add HCP", driver.getTitle()); driver.findElement(By.name("firstName")).sendKeys("Laurie"); driver.findElement(By.name("lastName")).sendKeys("Williams"); driver.findElement(By.name("email")).sendKeys("laurie@ncsu.edu"); driver.findElement(By.name("email")).submit(); String newMID = driver.findElement(By.className("fTable")).findElements(By.cssSelector("td")).get(1) .getText();//from w w w . j a va 2s.com driver.findElement(By.partialLinkText("Continue")).click(); assertEquals("iTrust - Edit Personnel", driver.getTitle()); driver.findElement(By.name("streetAddress1")).sendKeys("900 Main Campus Dr"); driver.findElement(By.name("streetAddress2")).sendKeys("Box 2509"); driver.findElement(By.name("city")).sendKeys("Raleigh"); Select select = new Select(driver.findElement(By.name("state"))); select.selectByValue("NC"); driver.findElement(By.name("zip")).sendKeys("27606-1234"); driver.findElement(By.name("phone")).sendKeys("919-100-1000"); driver.findElement(By.name("phone")).submit(); assertTrue(driver.getPageSource().contains("Information Successfully Updated")); assertLogged(TransactionType.LHCP_CREATE, 9000000001L, Long.parseLong(newMID), ""); }
From source file:edu.ncsu.csc.itrust.selenium.CreateHCPTest.java
public void testEditValidPersonnel() throws Exception { WebDriver driver = login("9000000001", "pw"); assertLogged(TransactionType.HOME_VIEW, 9000000001L, 0L, ""); assertEquals("iTrust - Admin Home", driver.getTitle()); driver.findElement(By.linkText("Edit Personnel")).click(); assertEquals("iTrust - Please Select a Personnel", driver.getTitle()); driver.findElement(By.name("FIRST_NAME")).sendKeys("Kelly"); driver.findElement(By.name("LAST_NAME")).sendKeys("Doctor"); driver.findElement(By.name("FIRST_NAME")).submit(); driver.findElement(By.cssSelector("input[value='9000000000']")).submit(); driver.findElement(By.name("city")).clear(); driver.findElement(By.name("city")).sendKeys("Brooklyn"); driver.findElement(By.name("city")).submit(); assertTrue(driver.getPageSource().contains("Information Successfully Updated")); assertLogged(TransactionType.LHCP_EDIT, 9000000001L, 9000000000L, ""); driver.findElement(By.linkText("Edit Personnel")).click(); assertEquals("iTrust - Please Select a Personnel", driver.getTitle()); }
From source file:edu.ncsu.csc.itrust.selenium.CreateHCPTest.java
public void testEditHospitalAssignments() throws Exception { gen.clearAllTables();// www . j ava 2 s. co m gen.standardData(); WebDriver driver = login("9000000001", "pw"); assertLogged(TransactionType.HOME_VIEW, 9000000001L, 0L, ""); assertEquals("iTrust - Admin Home", driver.getTitle()); driver.findElement(By.linkText("Edit HCP Assignment to Hospital")).click(); assertEquals("iTrust - Please Select a Personnel", driver.getTitle()); driver.findElement(By.name("FIRST_NAME")).sendKeys("Kelly"); driver.findElement(By.name("LAST_NAME")).sendKeys("Doctor"); driver.findElement(By.name("FIRST_NAME")).submit(); driver.findElement(By.cssSelector("input[value='9000000000']")).submit(); assertEquals("iTrust - Hospital Staffing Assignments", driver.getTitle()); driver.findElement(By.linkText("Assign")).click(); assertTrue(driver.getPageSource().contains("HCP has been assigned")); assertLogged(TransactionType.LHCP_ASSIGN_HOSPITAL, 9000000001L, 9000000000L, ""); driver.findElement(By.linkText("Unassign")).click(); assertTrue(driver.getPageSource().contains("HCP has been unassigned")); assertLogged(TransactionType.LHCP_REMOVE_HOSPITAL, 9000000001L, 9000000000L, ""); }