List of usage examples for org.openqa.selenium WebDriver close
void close();
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 w w w .ja va2s. co 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:edu.uci.ics.crawler4j.crawler.FirefoxWebCrawler.java
License:Apache License
public void run() { onStart();//w w w. ja va 2s . c o m File file = new File("output.csv"); FileWriter fw = null; PrintWriter bw = null; WebDriver driver = new FirefoxDriver(); try { if (file.exists()) { file.delete(); } file.createNewFile(); fw = new FileWriter(file.getAbsoluteFile()); } catch (IOException e) { e.printStackTrace(); } bw = new PrintWriter(fw); bw.append("Retailer,ID,Name,Price,Colour,Size,Stock,Category 1,Category 2,Sale,Image,Date,URL"); bw.append("\r\n"); while (true) { if (driver != null) { driver.close(); } driver = new FirefoxDriver(); bw = new PrintWriter(fw); List<WebURL> assignedURLs = new ArrayList<>(50); isWaitingForNewURLs = true; frontier.getNextURLs(50, assignedURLs); isWaitingForNewURLs = false; if (assignedURLs.size() == 0) { if (frontier.isFinished()) { bw.close(); driver.close(); return; } try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } } else { for (WebURL curURL : assignedURLs) { if (curURL != null) { processPage(curURL, fw, bw, driver); frontier.setProcessed(curURL); } if (myController.isShuttingDown()) { logger.info("Exiting because of controller shutdown."); bw.close(); driver.close(); return; } } } } }
From source file:edu.uci.ics.crawler4j.crawler.WebCrawler.java
License:Apache License
public void run() { onStart();/*from w w w. j ava 2 s . c o m*/ Date date = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); File file = new File(retailer + "_" + dateFormat.format(date) + ".csv"); FileWriter fw = null; PrintWriter bw = null; WebDriver driver = null; try { if (file.exists()) { file.delete(); } file.createNewFile(); fw = new FileWriter(file.getAbsoluteFile()); } catch (IOException e) { e.printStackTrace(); } bw = new PrintWriter(fw); bw.append("Retailer,ID,Name,Price,Colour,Size,Stock,Category 1,Category 2,Sale,Image,Date,URL"); bw.append("\r\n"); while (true) { driver = new HtmlUnitDriver(true); bw = new PrintWriter(fw); List<WebURL> assignedURLs = new ArrayList<>(50); isWaitingForNewURLs = true; frontier.getNextURLs(50, assignedURLs); isWaitingForNewURLs = false; if (assignedURLs.size() == 0) { if (frontier.isFinished()) { bw.close(); driver.close(); return; } try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } } else { for (WebURL curURL : assignedURLs) { if (curURL != null) { processPage(curURL, fw, bw, driver); frontier.setProcessed(curURL); } if (myController.isShuttingDown()) { logger.info("Exiting because of controller shutdown."); bw.close(); driver.close(); return; } } } } }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_15.</p> *//* www .j a va2 s .co m*/ public static void browserEngineTest_15() { FirefoxProfile profile = new FirefoxProfile( TestUtils.getWebdriverProfile("/home/cjneasbi/.mozilla/firefox", "webdriver")); WebDriver wdriver = new FirefoxDriver( new FirefoxBinary(new File("/home/cjneasbi/Desktop/old_firefox/firefox-14.0.1/firefox-bin")), profile); wdriver.get("http://www.cs.uga.edu/~neasbitt/"); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement elem = wdriver.findElement(By.id("logo")); JSUtils.setElementAttribute(wdriver, elem, "id", "logologologo1"); try { elem = wdriver.findElement(By.id("logologologo1")); System.out.println("Pass"); } catch (NoSuchElementException e) { System.out.println("Fail"); } wdriver.close(); }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_16.</p> * * @throws java.io.IOException if any./*from www.j a v a2s . c o m*/ * @throws java.lang.InterruptedException if any. */ public static void browserEngineTest_16() throws IOException, InterruptedException { FirefoxProfile profile = new FirefoxProfile( TestUtils.getWebdriverProfile("/home/cjneasbi/.mozilla/firefox", "webdriver")); WebDriver wdriver = new FirefoxDriver( new FirefoxBinary(new File("/home/cjneasbi/Desktop/old_firefox/firefox-17.0/firefox-bin")), profile); // WebDriver wdriver = new FirefoxDriver(); wdriver.get("http://www.cs.uga.edu/~neasbitt/"); wdriver.switchTo().activeElement(); Thread.sleep(10000); WebElement elem = wdriver.findElement(By.id("logo")); List<String> locator = JSUtils.getElementLocator(wdriver, elem); for (String s : locator) { System.out.println(s); } wdriver.close(); }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_18.</p> * * @throws java.io.IOException if any./* www .ja va 2 s . co m*/ * @throws java.lang.InterruptedException if any. */ public static void browserEngineTest_18() throws IOException, InterruptedException { FirefoxProfile profile = new FirefoxProfile( TestUtils.getWebdriverProfile("/home/cjneasbi/.mozilla/firefox", "webdriver")); WebDriver wdriver = new FirefoxDriver( new FirefoxBinary(new File("/home/cjneasbi/Desktop/old_firefox/firefox-17.0/firefox-bin")), profile); // WebDriver wdriver = new FirefoxDriver(); wdriver.get("http://www.cs.uga.edu/~neasbitt/"); wdriver.switchTo().activeElement(); Thread.sleep(5000); WebElement elem = wdriver.findElement(By.id("profile")); Map<String, String> attrs = JSUtils.getElementAttributes(wdriver, elem); System.out.println(attrs); wdriver.close(); }
From source file:edu.uga.cs.clickminer.test.ProxyClientTest.java
License:Open Source License
/** * <p>proxyClientTest_7.</p> * * @throws java.lang.Exception if any.// w w w . jav a 2 s .c om */ public static void proxyClientTest_7() throws Exception { FirefoxProfile profile = new FirefoxProfile( TestUtils.getWebdriverProfile("/home/cjneasbi/.mozilla/firefox", "webdriver")); WebDriver wdriver = new FirefoxDriver( new FirefoxBinary(new File("/home/cjneasbi/Desktop/old_firefox/firefox-14.0.1/firefox-bin")), profile, TestUtils.createProxyConfig()); ProxyClient pc = new ProxyClient("127.0.0.1", 8888); pc.setModeNoContent("http://www.newegg.com"); if (pc.getMode() == ProxyMode.NOCONTENT) { System.out.println("Pass"); } else { System.out.println("Fail"); } wdriver.get("http://www.yahoo.com"); Thread.sleep(2000); if (pc.getMode() == ProxyMode.NOCONTENT) { System.out.println("Pass"); } else { System.out.println("Fail"); } wdriver.get("http://www.newegg.com"); Thread.sleep(2000); if (pc.getMode() == ProxyMode.CONTENT) { System.out.println("Pass"); } else { System.out.println("Fail"); } wdriver.close(); }
From source file:edu.umd.cs.guitar.ripper.WebRipperMonitor.java
License:Open Source License
@Override public void closeWindow(GWindow window) { if (window instanceof WebWindow) { WebDriver driver = application.getDriver(); driver.switchTo().window(((WebWindow) window).getHandle()); driver.close(); driver.switchTo().window(windowManager.getLegalWindow()); windowManager.close(window);// w ww . j a va 2 s.c o m } }
From source file:edu.usc.cs.ir.htmlunit.handler.HtmlUnitWebDriver.java
License:Apache License
public static void cleanUpDriver(WebDriver driver) { if (driver != null) { try {/* w ww . j a v a 2s.c om*/ driver.close(); driver.quit(); TemporaryFilesystem.getDefaultTmpFS().deleteTemporaryFiles(); } catch (Exception e) { throw new RuntimeException(e); } } }
From source file:edu.usc.cs.ir.selenium.handler.Arguntrader.java
License:Apache License
public static void main(String[] args) { Arguntrader glocktalk = new Arguntrader(); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "localhost"); profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false"); profile.setPreference("permissions.default.stylesheet", 1); profile.setPreference("permissions.default.image", 1); FirefoxBinary binary = new FirefoxBinary(); binary.setTimeout(TimeUnit.SECONDS.toMillis(180)); WebDriver driver = new FirefoxDriver(binary, profile); driver.manage().timeouts().pageLoadTimeout(10000, TimeUnit.MILLISECONDS); try {// w w w .ja va2s . com driver.get("http://arguntrader.com/viewforum.php?f=8"); System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8"))); } catch (Exception e) { if (e instanceof TimeoutException) { System.out.println("Timeout Exception"); try { System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8"))); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } e.printStackTrace(); } finally { if (driver != null) { driver.close(); driver.quit(); } } }