List of usage examples for org.openqa.selenium WebDriver get
void get(String url);
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.PageNavigation.PageNavigationUK1.java
License:Apache License
public void processDriverForHipointfirearmsforums(WebDriver driver) { List<WebElement> search = driver.findElement(By.id("navigation")).findElements(By.tagName("a")); for (WebElement element : search) { String link = element.getAttribute("href"); if (link.contains("photo")) { driver.get(link); return; }//from www . j av a2 s . c om } }
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); 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();//from ww w .j a va2 s. com break LOOP; } } } } } JavascriptExecutor executor = (JavascriptExecutor) driver; executor.executeScript("document.body.innerHTML=document.body.innerHTML + \"" + data + "\";"); }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler9.java
License:Apache License
public void processDriver(WebDriver driver) { List<String> accumulatedData = new ArrayList<>(); //used to keep image tags from each page after click boolean paginationFound = false; boolean nextPageFound = false; System.err/*from w ww .j av a 2 s.c o m*/ .println("DallasGunsPaginationHandler: Entered default dallasguns.com/guns_online page!!!!!!!!!,"); String startPage = driver.getCurrentUrl(); driver.findElement(By.tagName("body")).getAttribute("innerHTML"); Configuration conf = NutchConfiguration.create(); try { long end = System.currentTimeMillis() + 5000; while (System.currentTimeMillis() < end) { //Check if this page has pagination element, if so, need to process List<WebElement> testDivs = null; testDivs = driver.findElements(new By.ById("pagination")); if (testDivs != null && testDivs.size() > 0) { WebElement paginationTest = testDivs.get(0); if (paginationTest != null) { paginationFound = true; System.err.println("DallasGunsPaginationHandler: " + driver.getCurrentUrl() + " found pagination!!!!!!!!!!!!!!!!"); break; } } } WebElement nextPage = null; List<WebElement> paginationDivs = null; List<WebElement> links = null; WebElement span = null; if (paginationFound) { paginationDivs = driver.findElements(new By.ById("pagination")); if (paginationDivs.size() > 0) { span = paginationDivs.get(0).findElement(new By.ByTagName("span")); if (span != null) { // System.err.println("DallasGunsPaginationHandler: found span!!!!!"); links = span.findElements(new By.ByTagName("a")); if (links != null && links.size() > 0) { System.err.println("DallasGunsPaginationHandler: found pagination links!!!!!"); nextPage = links.get(links.size() - 1); if (nextPage.getAttribute("title").equals("Next Page")) { System.err.println("DallasGunsPaginationHandler: found Next Page link at " + driver.getCurrentUrl() + "!!!!!!"); nextPageFound = true; } } } } } while (nextPageFound) { nextPage.click(); new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3)); System.err.println("DallasGunsPaginationHandler: Arrived at new URL: " + driver.getCurrentUrl() + " from click!!!!!!!"); List<WebElement> imgs = driver.findElements(new By.ByTagName("img")); if (imgs != null && imgs.size() > 0) { System.err.println("DallasGunsPaginationHandler: Found new Images at " + driver.getCurrentUrl() + "!!!!!!!"); for (int j = 0; j < imgs.size(); j++) { String newImgSrc = imgs.get(j).getAttribute("src"); //String newImageTag = "<a href='"+newImgSrc+"'> another gun img </a>"; accumulatedData.add(newImgSrc); //accumulatedData+=newImageTag; System.err.println("DallasGunsPaginationHandler: updated accumulatedData with + " + newImgSrc + "!!!!!!!!!"); } } paginationDivs = driver.findElements(new By.ById("pagination")); if (paginationDivs.size() > 0) { span = paginationDivs.get(0).findElement(new By.ByTagName("span")); if (span != null) { // System.err.println("DallasGunsPaginationHandler: found span!!!!!"); links = span.findElements(new By.ByTagName("a")); if (links != null && links.size() > 0) { System.err.println("DallasGunsPaginationHandler: found pagination links!!!!!"); nextPage = links.get(links.size() - 1); if (nextPage.getAttribute("title").equals("Next Page")) { System.err.println("DallasGunsPaginationHandler: found Next Page link at " + driver.getCurrentUrl() + "!!!!!!"); nextPageFound = true; } else { nextPageFound = false; } } else { nextPageFound = false; } } else { nextPageFound = false; } } else { nextPageFound = false; } } if (accumulatedData.size() > 0) { //append images data to driver so that it can be processed by parser //navigating back to original page driver.get(startPage); System.err.println("DallasGunsPaginationHandler: navigated back to start page " + driver.getCurrentUrl() + "!!!!!!"); new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3)); System.err.println("DallasGunsPaginationHandler: appending new data!!!!!!!!"); JavascriptExecutor jsx = (JavascriptExecutor) driver; for (String src : accumulatedData) { jsx.executeScript("var aTag = document.createElement('a'); aTag.setAttribute('href',\"" + src + "\"); aTag.innerText = \"gun image\"; document.body.appendChild(aTag);"); //jsx.executeScript("aTag.setAttribute('href','"+src+"');"); //jsx.executeScript("aTag.innerText = 'gun image');"); //jsx.executeScript("document.body.appendChild(aTag);"); } //jsx.executeScript("document.body.innerHTML+= "+ accumulatedData+";"); } System.err.println("DallasGunsIndexHandler: Finished Pagination Handler at " + driver.getCurrentUrl() + "!!!!!!!!!!!!"); } catch (Exception e) { System.err.println("ERROR: DallasGunsIndexHandler @" + driver.getCurrentUrl() + e.getMessage()); } }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandlerUK1.java
License:Apache License
public boolean shouldProcessURL(String URL) { System.out.println("---------SAMI SELENIUM VERSION-----------"); System.out.println(URL); WebDriver driver = new FirefoxDriver(); driver.get(URL); //Handling of [HTTP 401 Responses] for Login if(URL.contains("https://www.impactguns.com/login.aspx")){ doLogin(driver,"samidakhani@gmail.com","alibhai","ctl00_ctl00_MainContent_uxLogin_uxLogin_UserName","ctl00_ctl00_MainContent_uxLogin_uxLogin_Password", "ctl00_ctl00_MainContent_uxLogin_uxLogin_ibLogin",false,false,false,true); }else if(URL.contains("http://floridaguntrader.com/index.php?a=10")){ doLogin(driver,"samidakhani","alibhai","username", "password", "submit", false, false, true, false); }else if(URL.contains("http://www.gunidaho.com/site/login.htm")){ doLogin(driver,"samidakhani@gmail.com","gpmvgeviczyi","User_email","User_password","btnLogin", false, false, true, false); }else if(URL.contains("http://www.idahogunsforsale.com/classifieds/index.php?a=10")){ doLogin(driver,"samidakhani","alibhai","username","password","submit", false, false, true,false); }else if(URL.contains("http://www.kyclassifieds.com/login/")){ doLogin(driver,"samidakhani","alibhai", "login_username", "login_password","login", true, true,true, false); }/*from w w w .j a va 2s.com*/ else if(URL.contains("page")){ doPagination(driver, URL); } }
From source file:gov.nasa.jpl.nutch.phantomjs.PhantomJSWebClient.java
License:Apache License
public static WebDriver getDriverForPage(String url) { long pageLoadTimout = 3; DesiredCapabilities caps = new DesiredCapabilities(); caps.setJavascriptEnabled(true);/*w w w .ja v a 2 s.co m*/ caps.setCapability("takesScreenshot", false); WebDriver driver = null; try { driver = new PhantomJSDriver(caps); driver.manage().timeouts().pageLoadTimeout(pageLoadTimout, TimeUnit.SECONDS); driver.get(url); } catch (Exception e) { if (e instanceof TimeoutException) { System.out.println("PhantomJS WebDriver: Timeout Exception: Capturing whatever loaded so far..."); return driver; } cleanUpDriver(driver); throw new RuntimeException(e); } return driver; }
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); String accessToken;/*w ww. ja v a 2 s. c o m*/ 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 main(String[] args) throws InterruptedException, FileNotFoundException, IOException { setProps();//from w w w .j av a 2 s . c o m FirefoxOptions options = new FirefoxOptions().setProfile(new FirefoxProfile()); Proxy proxy = new Proxy(); proxy.setProxyType(Proxy.ProxyType.AUTODETECT); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("proxy", proxy); WebDriver driver = new FirefoxDriver(capabilities); driver.get("https://sise2mx.ikeasistencia.com/"); driver.findElement(By.id("Usr")).clear(); driver.findElement(By.id("Usr")).sendKeys("cmantenimiento"); driver.findElement(By.id("Pass")).clear(); driver.findElement(By.id("Pass")).sendKeys(readPass()); driver.findElement(By.id("btnLogin")).click(); for (int i = 0; i < 1; i = 0) { Thread.sleep(3100); if ((isElementPresent(("//*[@id=\"PW_LST\"]/tbody/tr[3]/td[10]/button"), driver)) == true) { driver.findElement(By.xpath("//*[@id=\"PW_LST\"]/tbody/tr[3]/td[10]/button")).click(); System.out.println("Has aceptado un nuevo expediente."); System.out.println("Fecha: " + timeStamp()); //msg(); } if ((isElementPresent(("//*[@id=\"msg_alerta\"]/table/tbody/tr/td/table/tbody/tr[4]/td/button"), driver)) == true) { driver.findElement( By.xpath("//*[@id=\"msg_alerta\"]/table/tbody/tr/td/table/tbody/tr[4]/td/button")).click(); if ((isElementPresent(("//*[@id=\"PW_LST\"]/tbody/tr[3]/td[10]/button"), driver)) == true) { driver.findElement(By.xpath("//*[@id=\"PW_LST\"]/tbody/tr[3]/td[10]/button")).click(); } System.out.println("Has aceptado un nuevo expediente."); System.out.println("Fecha: " + timeStamp()); //msg(); } if ((isElementPresent(("//*[@id=\"MensajeTimeOut\"]/table"), driver)) == true) { driver.findElement( By.xpath("//*[@id=\"MensajeTimeOut\"]/table/tbody/tr/td/table/tbody/tr[4]/td[2]/button")) .click(); } else { driver.findElement(By.xpath("//div[2]/div[2]/table/tbody/tr/td")).click(); } } }
From source file:ike.Ike.java
public static void msg() throws InterruptedException { WebDriver driver2 = new FirefoxDriver(); driver2.get( "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);/*from w w w . jav a2 s. co m*/ 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 .j a va2 s . co 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:injector.psm.googlecode.GoogleCodeInjector.java
public GoogleCodeProject injectProject(String projectURL) { GoogleCodeProject project = GooglecodeFactory.eINSTANCE.createGoogleCodeProject(); WebDriver driver = getDriver(); driver.get(projectURL); // 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);/*from w w w . j a va 2s . c o m*/ 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; }