List of usage examples for org.openqa.selenium WebDriver quit
void quit();
From source file:GlennsPack.GlennWebAPI.Example.java
License:Open Source License
public static void testGoogleSearch() { // Optional, if not specified, WebDriver will search your path for chromedriver. System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://whatismybrowser.com"); try {//from w ww. j a v a 2 s. co m Thread.sleep(5000); } catch (InterruptedException e) { // FIXME Auto-generated catch block e.printStackTrace(); } // Let the user actually see something! WebElement searchBox = driver.findElement(By.name("q")); searchBox.sendKeys("ChromeDriver"); searchBox.submit(); try { Thread.sleep(5000); } catch (InterruptedException e) { // FIXME Auto-generated catch block e.printStackTrace(); } // Let the user actually see something! driver.quit(); }
From source file:google.TestGoogle.java
/** * @param args the command line arguments *///from w w w. jav a2 s . c o m public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver", "D:\\GitHub\\java\\Gradle\\SeleniumTest\\exe\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.get("http://bbs.sgcn.com/member.php?mod=logging&action=login"); Thread.sleep(5000); // Let the user actually see something! //WebElement searchBox = driver.findElement(By.name("q")); //searchBox.sendKeys("ChromeDriver"); //searchBox.submit(); driver.findElement(By.id("u_u")).sendKeys("?"); driver.findElement(By.id("u_p")).sendKeys("diesel"); driver.findElement(By.className("u_s1")).submit(); Thread.sleep(5000); driver.findElement(By.className("bind_skip")).submit(); driver.get("http://bbs.sgcn.com/thread-15716879-1-1.html"); JavascriptExecutor jse = (JavascriptExecutor) driver; WebElement we = driver.findElement(By.id("fastpostsubmit")); jse.executeScript("arguments[0].scrollIntoView(true);", we); driver.findElement(By.id("fastpostsubmit")).click(); Thread.sleep(5000); // Let the user actually see something! driver.quit(); }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandler21.java
License:Apache License
public boolean shouldProcessURL(String URL) { System.out.print("============SELENIUM================="); System.out.println("DEBUG:::::" + URL); System.setProperty("webdriver.firefox.bin", "/Applications/Firefox.app/Contents/MacOS/firefox"); WebDriver driver = new FirefoxDriver(); // And now use this to visit Google driver.get(URL);/*from w w w .j a v a 2 s . c om*/ try { String url1, url2, url3, url4; url1 = "www.arguntrader.com/ucp.php?mode=login"; url2 = "www.buyusedguns.net/login.php"; url3 = "www.hawaiiguntrader.com/login/"; url4 = "www.gunidaho.com/site/login.htm"; WebElement username; WebElement password; WebElement submit; if (URL.contains(url1)) { System.out.println(url1 + " :***************************login page***********************************************8"); username = driver.findElement(By.id("username")); username.sendKeys("bhanuprasad"); password = driver.findElement(By.id("password")); password.sendKeys("lasvegas"); submit = driver.findElement(By.name("login")); submit.submit(); } else if (URL.contains(url2)) { System.out.println(url2 + " :***************************login page***********************************************8"); username = driver.findElement(By.id("username")); username.sendKeys("bhanuirprasadir"); password = driver.findElement(By.id("password")); password.sendKeys("bhanu@prasad"); submit = driver.findElement(By.id("submit")); submit.submit(); } else if (URL.contains(url3)) { System.out.println(url3 + " :***************************login page***********************************************8"); username = driver.findElement(By.id("login_username")); username.sendKeys("bhanuir.prasadir@gmail.com"); password = driver.findElement(By.id("login_password")); password.sendKeys("bhanu@prasad"); submit = driver.findElement(By.id("login")); submit.submit(); } else if (URL.contains(url4)) { System.out.println(url4 + " :***************************login page***********************************************8"); username = driver.findElement(By.id("User_email")); username.sendKeys("bhanuir.prasadir@gmail.com"); password = driver.findElement(By.id("User_password")); password.sendKeys("vcytaybmabzk"); submit = driver.findElement(By.name("btnLogin")); submit.submit(); } else if (URL.contains("page")) { System.out.println(URL + " :************************pagination page***********************************************8"); if (URL.contains("http://www.shooting.org/")) driver.findElement(By.xpath("//a[@rel='next']")); else if (URL.contains("https://www.alphacatarmory.com/")) driver.findElement(By.className("next")); else if (URL.contains("http://www.budsgunshop.com/catalog/")) driver.findElement(By.xpath("//a[@class='pageResults' and @title=' Next Page ']")); } else if ((URL.contains("www.store.kimberamerica.com/customer/account/login")) || (URL.contains("www.palmettostatearmory.com/index.php/customer/account/login/")) || (URL.contains("www.osagecountyguns.com/customer/account/login/")) || (URL.contains("www.sogknives.com/customer/account/login/")) || (URL.contains("www.budsgunshop.com/catalog/login.php"))) { System.out.println( "***************************login page***********************************************8"); WebElement email_element = driver.findElement(By.id("email")); email_element.sendKeys("las567vegas@gmail.com"); WebElement pass_element = driver.findElement(By.id("pass")); pass_element.sendKeys("lasvegas"); WebElement submit_element = driver.findElement(By.id("send2")); submit_element.submit(); } } catch (Exception e) { driver.quit(); System.out.println("In exception!!!" + e); } return true; }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandler8.java
License:Apache License
public void processDriver(WebDriver driver) { URL url;//from w w w . j av a 2s .c o m InputStream is = null; BufferedReader br; String lineContent; PrintWriter writer = null; String currentURL = null; driver.get(url1); try { writer = new PrintWriter("theFile" + i + ".txt", "UTF-8"); i++; } catch (IOException ex) { System.out.println("Something wrong with the PrintWriter"); } try { url = new URL(url1); is = url.openStream(); br = new BufferedReader(new InputStreamReader(is)); while ((lineContent = br.readLine()) != null && writer != null) { writer.println(lineContent); } } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { if (is != null) is.close(); } catch (IOException ioe) { } } if (writer != null) { writer.close(); } if (url1.equals("http://www.theoutdoorstrader.com")) { driver.findElement(By.value("loginBar")).click(); driver.findElement(By.id("LoginControl")).sendKeys("will"); driver.findElement(By.id("ctrl_password")).sendKeys("will"); driver.findElement(By.value("Log in")).click(); } currentURL = driver.getCurrentUrl(); try { writer = new PrintWriter("theFile" + i + ".txt", "UTF-8"); i++; } catch (IOException ex) { System.out.println("Something wrong with the PrintWriter"); } try { url = new URL(currentURL); is = url.openStream(); br = new BufferedReader(new InputStreamReader(is)); while ((lineContent = br.readLine()) != null && writer != null) { writer.println(lineContent); } } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { if (is != null) is.close(); } catch (IOException ioe) { } } if (writer != null) { writer.close(); } driver.quit(); }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.PageNavigation.PageNavigationUK1.java
License:Apache License
public void processDriverForIwanna(WebDriver driver) { String data = ""; String nextLink = ""; String[] keywords = { "rifle", "hawk", "gun", "pistol", "firearm", "grenade", "bomb", "sniper", "sword", "knife", "knives", "flamethrower", "carbine", "revolver", "missile", "barrel", "bullet", "gunpowder", "muzzle", "trigger", "weapon", "ammo", "ammunition" }; List<WebElement> elements = driver.findElement(By.id("tag_cloud")).findElements(By.tagName("a")); for (WebElement element : elements) { String link = element.getAttribute("href"); LOOP: for (String key : keywords) { if (link.contains(key)) { WebDriver travel = new FirefoxDriver(); travel.get(link);//from w ww . ja va 2 s . c om while (true) { try { List<WebElement> listings = travel.findElements(By.className("listing")); for (WebElement listing : listings) data += listing.findElement(By.className("column70")).findElement(By.tagName("a")) .getAttribute("href") + " "; JavascriptExecutor executor = (JavascriptExecutor) travel; nextLink = travel.findElement(By.className("next")).getAttribute("onclick") + ";"; executor.executeScript(nextLink); } catch (Exception e) { travel.quit(); break LOOP; } } } } } JavascriptExecutor executor = (JavascriptExecutor) driver; executor.executeScript("document.body.innerHTML=document.body.innerHTML + \"" + data + "\";"); }
From source file:GUI.AfterLogin.java
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: String domain = "http://google.com"; String appId = "1716266622025825"; String authUrl = "https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=" + appId + "&redirect_uri=" + domain + "&scope=user_about_me," + "user_actions.books,user_actions.fitness,user_actions.music,user_actions.news,user_actions.video,user_birthday,user_education_history," + "user_events,user_photos,user_friends,user_games_activity,user_hometown,user_likes,user_location,user_photos,user_relationship_details," + "user_relationships,user_religion_politics,user_status,user_tagged_places,user_videos,user_website,user_work_history,ads_management,ads_read,email," + "manage_pages,publish_actions,read_insights,read_page_mailboxes,rsvp_event"; System.setProperty("webdirver.chrome.driver", "chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get(authUrl);//from w ww . j a va 2 s .c om String accessToken; while (true) { if (!driver.getCurrentUrl().contains("facebook.com")) { String url = driver.getCurrentUrl(); accessToken = url.replaceAll(".*#access_token=(.+)&.*", "$1"); driver.quit(); fbClient = new DefaultFacebookClient(accessToken); try { // Obtem os dados do utilizador UserData userdata = new UserData(fbClient); user = userdata.getUser("me"); Interface it = new Interface(); this.jButton2.setEnabled(true); this.jButton3.setEnabled(true); this.textField.setEnabled(true); this.jComboBox1.setEnabled(true); this.jComboBox2.setEnabled(true); this.jComboBox3.setEnabled(true); this.jLabel3.setEnabled(true); this.jLabel4.setEnabled(true); this.jLabel7.setEnabled(true); this.jLabel11.setEnabled(true); this.jButton4.setEnabled(false); this.setName(user.getName()); } catch (Exception e) { e.printStackTrace(); } } } }
From source file:ike.Ike.java
public static void msg() throws InterruptedException { WebDriver driver2 = new FirefoxDriver(); driver2.get(//from w w w . j a v a 2 s. c o m "https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1#identifier"); driver2.findElement(By.id("Email")).clear(); driver2.findElement(By.id("Email")).sendKeys("serviciosycerrajerias@gmail.com"); driver2.findElement(By.id("next")).click(); Thread.sleep(2000); driver2.findElement(By.id("Passwd")).clear(); driver2.findElement(By.id("Passwd")).sendKeys("tomaservicios"); driver2.findElement(By.id("signIn")).click(); Thread.sleep(13000); driver2.findElement(By.className("z0")).click(); Thread.sleep(2000); driver2.findElement(By.name("to")).click(); driver2.findElement(By.name("to")).clear(); driver2.findElement(By.name("to")).sendKeys("serviciosycerrajerias@gmail.com"); driver2.findElement(By.name("subjectbox")).click(); driver2.findElement(By.name("subjectbox")).clear(); driver2.findElement(By.name("subjectbox")).sendKeys("Nuevo expediente: " + mTimestamp); driver2.findElement(By.xpath("//td/div/div/div[4]/table/tbody/tr/td/div/div[2]")).click(); driver2.quit(); }
From source file:imagedownload.Downloader.java
public void download() { System.out.println((new Date()).toString()); WebDriver driver = new ChromeDriver(); WebDriver.Window win = driver.manage().window(); // get the full screen size (exculde desktop toolbar) win.maximize();/*from w w w .ja v a 2 s.c o m*/ int screenHeight = win.getSize().getHeight(); int screenWidth = win.getSize().getWidth(); System.out.println("Screen: " + screenHeight + "*" + screenWidth); // set browser size and position it to bottom right win.setSize(new Dimension(browserWidth, browserHeight)); System.out.println("Browser: " + win.getSize().getHeight() + "*" + win.getSize().getWidth()); win.setPosition(new Point(screenWidth - browserWidth, screenHeight - browserHeight)); // position the browser outside of windows if (hide) { win.setPosition(new Point(screenWidth, screenHeight)); } String page = firstPage; boolean hasNextPage = true; int pageCnt = 0; while (hasNextPage && pageCnt < pageLimit) { pageCnt++; if (visitedPages.get(page) != null) { System.out.println("Looped back. Quit download."); break; } visitedPages.put(page, page); driver.get(page); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); hasNextPage = false; if (pagination) { // if no xpath configured, default search all <a> hyperlinks if (xpath == null || xpath.trim().equals("")) { xpath = determineNextPage(driver); } if (xpath != null && !xpath.trim().equals("")) { page = ""; System.out.println("Xpath: " + xpath); List<WebElement> checkList = driver.findElements(By.xpath(xpath)); for (WebElement elm : checkList) { String text = elm.getAttribute("innerHTML"); for (String t : next) { if (text.equals(t)) { hasNextPage = true; page = elm.getAttribute("href"); break; } } } System.out.println("Next page: " + hasNextPage + ", " + page); } } List<WebElement> imgList = driver.findElements(By.tagName("img")); List<String> filteredList = new ArrayList<String>(); for (WebElement img : imgList) { if (img.getAttribute("src") == null) { continue; } if (duplicateFilter) { if (savedImages.get(img.getAttribute("src")) != null) { continue; } } if (minSizeFilter) { if (img.getSize().getHeight() < minHeight || img.getSize().getWidth() < minWidth) { continue; } } filteredList.add(img.getAttribute("src").trim()); } int cnt = 0; InputStream imgIn = null; OutputStream imgOut = null; for (String location : filteredList) { cnt++; try { String[] urlArr = location.split("\\/"); String[] nameArr = urlArr[urlArr.length - 1].split("\\."); String ext = nameArr[nameArr.length - 1]; String filePath = config.getProperty("output.folder") + config.getProperty("output.namePrefix") + "_" + pageCnt + "_" + cnt + "." + ext; System.out.println("File location: " + location); System.out.println("File name: " + urlArr[urlArr.length - 1]); System.out.println("File ext: " + nameArr[nameArr.length - 1]); System.out.println("Output: " + filePath); driver.get(location); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); WebElement image = driver.findElement(By.tagName("img")); System.out.println("Image element: " + image.getAttribute("src")); AutoSave.save(driver, image, filePath); savedImages.put(location, location); } finally { try { if (imgIn != null) { imgIn.close(); } if (imgOut != null) { imgOut.close(); } } catch (IOException ex) { Logger.getLogger(Downloader.class.getName()).log(Level.SEVERE, null, ex); } } } } driver.quit(); System.out.println((new Date()).toString()); }
From source file:io.appium.java_client.pagefactory_tests.DesktopBrowserCompatibilityTest.java
License:Apache License
private void test() { WebDriver driver = new ChromeDriver(); try {//from w w w . j ava2 s . com PageFactory.initElements(new AppiumFieldDecorator(driver, 15, TimeUnit.SECONDS), this); driver.get(new File("src/test/java/io/appium/java_client/hello appium - saved page.htm").toURI() .toString()); assertNotEquals(0, foundLinks.size()); assertNotEquals(0, main.size()); assertEquals(null, trap1); assertEquals(null, trap2); } finally { driver.quit(); } }
From source file:io.fabric8.selenium.SeleniumTests.java
License:Apache License
public static <T> T assertWebDriverForService(KubernetesClient client, String namespace, String serviceName, Function<WebDriverFacade, T> block) throws Exception { WebDriver driver = createWebDriver(); try {//from www .j av a 2 s . c o m WebDriverFacade facade = new WebDriverFacade(driver, client, namespace); facade.navigateToService(serviceName); T apply = block.apply(facade); String property = Systems.getEnvVarOrSystemProperty(WAIT_AFTER_SELENIUM); if (property != null) { long millis = 0; try { millis = Long.parseLong(property); } catch (NumberFormatException e) { logWarn("Env var / system property " + WAIT_AFTER_SELENIUM + " is not a long value: " + property + ". " + e, e); } if (millis > 0) { logInfo("Sleeping for " + millis + " millis before tearning down the test case"); try { Thread.sleep(millis); } catch (InterruptedException e) { // ignore } } } return apply; } catch (Exception e) { logError("Failed with exception: ", e); throw e; } finally { driver.quit(); } }