List of usage examples for org.openqa.selenium WebDriver close
void close();
From source file:edu.usc.cs.ir.selenium.handler.Glocktalk.java
License:Apache License
public static void main(String[] args) { Glocktalk glocktalk = new Glocktalk(); 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 {/* ww w . jav a 2s . c o m*/ driver.get("http://www.glocktalk.com/media?page=6"); 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(); } } }
From source file:edu.usc.cs.ir.selenium.handler.GlocktalkBasic.java
License:Apache License
public static void main(String[] args) { GlocktalkBasic glocktalk = new GlocktalkBasic(); WebDriver driver = new FirefoxDriver(); try {//from w w w . jav a 2 s.c o m driver.get("http://www.glocktalk.com/forum/general-firearms-forum.82/"); System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8"))); } catch (Exception e) { e.printStackTrace(); } finally { if (driver != null) { driver.close(); driver.quit(); } } }
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(); 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);/*from w ww .ja v a2 s. c om*/ 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:fr.jetoile.demo.breizhcamp.webapp.util.ShutdownHook.java
License:Apache License
@Override public synchronized void start() { adapter.forceQuit();//from ww w . ja v a 2 s.co m if (!WebDriverFactory.webDriverInstances.isEmpty()) { for (WebDriver webDriver : WebDriverFactory.webDriverInstances.values()) { if (webDriver != null) { webDriver.close(); } } } }
From source file:GlennsPack.GlennWebAPI.Example.java
License:Open Source License
public void twitterSpam() { System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().setSize(new Dimension(2000, 800)); driver.get("https://twitter.com/login"); driver.findElement(By.xpath("//*[@id=\"page-container\"]/div/div[1]/form/fieldset/div[1]/input")) .sendKeys("kakansbot"); driver.findElement(By.xpath("//*[@id=\"page-container\"]/div/div[1]/form/fieldset/div[2]/input")) .sendKeys("falcor1122"); driver.findElement(By.xpath("//*[@id=\"page-container\"]/div/div[1]/form/div[2]/button")).click(); millisAtStart = System.currentTimeMillis(); try {/*from w w w . j av a2s . co m*/ for (int i = 0; i < 100; i++) { str = ""; for (int i1 = 0; i1 < 10; i1++) { str = str + abc.charAt(rand.nextInt(abc.length())); } driver.findElement(By.xpath("//*[@id=\"global-new-tweet-button\"]")).click(); try { Thread.sleep(500); } catch (InterruptedException e) { // FIXME Auto-generated catch block e.printStackTrace(); } driver.findElement(By.id("tweet-box-global")).sendKeys(str); try { Thread.sleep(500); } catch (InterruptedException e) { // FIXME Auto-generated catch block e.printStackTrace(); } driver.findElement( By.xpath("//*[@id=\"global-tweet-dialog-dialog\"]/div[2]/div[4]/form/div[2]/div[2]/button")) .click(); x++; System.out.println("Nu har " + x + " tweets skickats, " + (int) ((System.currentTimeMillis() - millisAtStart) / 1000) + " sekunder efter start"); if (lastMillis > 0) { System.out.println("Senaste tweetet skickades fr " + (int) ((System.currentTimeMillis() - lastMillis) / 1000) + " sekunder sen"); } lastMillis = System.currentTimeMillis(); System.err.println(""); try { Thread.sleep(1000); } catch (InterruptedException e) { // FIXME Auto-generated catch block e.printStackTrace(); } } } catch (Exception e) { driver.close(); twitterSpam(); } driver.close(); }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandler30.java
License:Apache License
public void processDriver(WebDriver driver) { try {// w w w . j a va 2 s . co m if (currenturl.contains("http://forum.xencentral.com") || currenturl.contains("http://www.theoutdoorstrader.com") || currenturl.contains("http://xenforo.com") || currenturl.contains("http://worldwidesurvival.com")) { Configuration conf = NutchConfiguration.create(); new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3)); if (currenturl.contains("http://xenforo.com")) { WebElement visibleele = driver.findElement(By.xpath("//a[@href='login/']")); if (visibleele != null) visibleele.click(); else return; } WebElement passele = driver.findElement(By.xpath("//input[@type='password']")); WebElement userele = driver.findElement(By.xpath("//input[@name='login']")); WebElement submitele = driver.findElement(By.xpath("//input[@type='submit']")); if (passele != null && userele != null && submitele != null) { passele.sendKeys("Keys"); userele.sendKeys("Username"); submitele.click(); } else { System.out.println("fetch of " + currenturl + " failed with: Http code=403, url=" + currenturl); } driver.close(); } else { return; } } catch (Exception e) { LOG.info(StringUtils.stringifyException(e)); } }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandler35.java
License:Apache License
public void processDriver(WebDriver driver) { String cur = driver.getCurrentUrl(); if (cur.contains("/members/") || cur.contains("slickguns.com/alerts/")) { Configuration conf = NutchConfiguration.create(); new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3)); // Wait for the page to load try {/*from www. j av a 2s . co m*/ WebElement uname = driver.findElement(By.cssSelector("input[type=\"text\"]")); // handling multiple text boxes not needed for these pages WebElement remember = driver.findElement(By.cssSelector("input[type=\"checkbox\"]")); WebElement pwd = driver.findElement(By.cssSelector("input[type=\"password\"]")); uname.sendKeys("team35csci572@outlook.com"); // login info for all 403s pwd.sendKeys("qwer1234"); remember.click(); // Check Remember Me option :) pwd.submit(); } catch (Exception e) { } driver.navigate().refresh(); // new WebDriverWait(driver, 5)) // wait for click and any ending client process to compete execution (we are being generous here) } driver.close(); }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.misc.MiscHandler1.java
License:Apache License
public void processDriver(WebDriver driver) { FirefoxProfile p = new FirefoxProfile(); p.setPreference("webdriver_firefox_port", 8054); String URL = driver.getCurrentUrl(); Site site = this.matches(URL); if (site == null) return;// w ww.ja va2 s . c o m System.out.println("Processing: " + URL); driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); List<Action> actions = site.getActions(); for (Action action : actions) { String actionType = action.getType(); if (actionType.equals("input")) { WebElement element = findWebElement(action.getBy(), action.getValue(), driver); if (element == null) return; element.sendKeys(action.getKey()); } else if (actionType.equals("click")) { WebElement element = findWebElement(action.getBy(), action.getValue(), driver); if (element == null) return; element.click(); //Wait for a potential new page to load //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } else if (actionType.equals("redirect-append")) { //driver.navigate().to(action.getValue()); //driver.get(action.getValue());//Exactly same as the above driver.get(URL + action.getValue()); //Wait for a potential new page to load /* { Thread.sleep(10000); } catch(Exception e) { e.printStackTrace(); }*/ } driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); } driver.close(); }
From source file:gov.nih.nci.firebird.commons.selenium2.test.WebDriverModule.java
License:Open Source License
private void closeDriverOnShutdown(final WebDriver driver) { Runtime.getRuntime().addShutdownHook(new Thread() { @Override/*from w w w .ja va 2s . c o m*/ public void run() { driver.close(); } }); }
From source file:injector.psm.googlecode.GoogleCodeInjector.java
public GoogleCodeProject injectProject(String projectURL) { GoogleCodeProject project = GooglecodeFactory.eINSTANCE.createGoogleCodeProject(); WebDriver driver = getDriver(); driver.get(projectURL);/* ww w. j ava2s.com*/ // Info from the header WebElement headerElement = driver.findElement(By.className("headbg")); WebElement nameElement = headerElement.findElement(By.id("pname")); String name = nameElement.getText(); project.setName(name); WebElement summaryElement = headerElement.findElement(By.id("project_summary_link")); String summary = summaryElement.getText(); project.setSummary(summary); // Info from left column WebElement leftElement = driver.findElement(By.className("pscolumnl")); // TODO fix this /*WebElement starElement = leftElement.findElement(By.id("star_count")); int stars = Integer.valueOf(starElement.getText()); project.setStars(stars);*/ List<WebElement> psmetaElements = driver.findElements(By.className("psmeta")); if (psmetaElements.size() > 2) { WebElement licenseElement = psmetaElements.get(2); String license = licenseElement.getText(); project.setLicense(license); } WebElement projectLabelsElement = leftElement.findElement(By.id("project_labels")); List<WebElement> labelElements = projectLabelsElement.findElements(By.className("label")); for (WebElement labelElement : labelElements) { String labelName = labelElement.getText(); GoogleProjectLabel projectLabel = getProjectLabel(labelName); project.getLabels().add(projectLabel); } List<WebElement> userElements = leftElement.findElements(By.className("userlink")); for (WebElement userElement : userElements) { String username = userElement.getText(); GoogleUser user = getUser(username); project.getMembers().add(user); } // Info from the main column (right) WebElement rightElement = driver.findElement(By.id("wikicontent")); String description = rightElement.getText(); project.setDescription(description); // The rest GoogleIssueTracker issueTracker = GooglecodeFactory.eINSTANCE.createGoogleIssueTracker(); issueTracker.setUrl(projectURL + "/issues"); project.setIssueTracker(issueTracker); GoogleWiki wiki = GooglecodeFactory.eINSTANCE.createGoogleWiki(); project.setWiki(wiki); driver.close(); return project; }