List of usage examples for org.openqa.selenium WebDriver getCurrentUrl
String getCurrentUrl();
From source file:edu.uga.cs.clickminer.datamodel.log.PageEntry.java
License:Open Source License
/** * <p>getPageEntry.</p>/*from w ww . j a va2 s.c o m*/ * * @param wdriver a {@link org.openqa.selenium.WebDriver} object. * @param windowIMap a {@link edu.uga.cs.clickminer.index.WindowInteractionIndex} object. * @param windowhandle a {@link java.lang.String} object. */ public static PageEntry getPageEntry(WebDriver wdriver, WindowInteractionIndex windowIMap, String windowhandle) { WindowEntry winentry = new WindowEntry(windowhandle, windowIMap.getWindowOpener(windowhandle)); List<FrameEntry> entries = new ArrayList<FrameEntry>(); return new PageEntry(winentry, entries, wdriver.getCurrentUrl()); }
From source file:edu.uga.cs.clickminer.datamodel.WindowState.java
License:Open Source License
/** * <p>Constructor for WindowState.</p> * * @param pclient a {@link edu.uga.cs.clickminer.ProxyClient} object. * @param wdriver a {@link org.openqa.selenium.WebDriver} object. * @param windowHandle a {@link java.lang.String} object. * @param hashAlgo a {@link java.lang.String} object. * @param minSameRequestAndPage a int./*from w w w. ja v a2s . co m*/ * @param minNoNewRequests a int. * @param checkLimit a int. */ public WindowState(ProxyClient pclient, WebDriver wdriver, String windowHandle, String hashAlgo, int minSameRequestAndPage, int minNoNewRequests, int checkLimit) { super(LogFactory.getLog(WindowState.class), hashAlgo); this.pclient = pclient; this.wdriver = wdriver; this.windowHandle = windowHandle; if (minSameRequestAndPage < 1 || minNoNewRequests < 1 || checkLimit < 1) { throw new BrowserStateException( "minSameRequestAndPage, minNoNewRequests, and " + "checkLimit must have positive values"); } this.minSameRequestAndPage = minSameRequestAndPage; this.minNoNewCompletedRequests = minNoNewRequests; this.checkLimit = checkLimit; wdriver.switchTo().window(this.windowHandle); this.title = wdriver.getTitle(); this.url = wdriver.getCurrentUrl(); }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_10.</p> *///from w ww.j a v a 2s . co m public static void browserEngineTest_10() { FirefoxProfile profile = new FirefoxProfile( TestUtils.getWebdriverProfile("/home/cjneasbi/.mozilla/firefox", "webdriver")); WebDriver wdriver = new FirefoxDriver(null, profile); wdriver.get("http://www.dkfjaojfko.com"); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(wdriver.getCurrentUrl()); System.out.println(wdriver.getTitle()); System.out.println(wdriver.getPageSource()); wdriver.quit(); }
From source file:edu.uga.cs.clickminer.util.FrameUtils.java
License:Open Source License
/** * Recursive helper method of findFramePaths(String srcurl). * //from w ww .j a v a2 s. co m * @param wdriver * the WebDriver object to use * @param srcurl * the source url, if null matches all paths * @param curpath * the currently explored path * @param buf * the list of paths to populate */ private static void findFramePaths(WebDriver wdriver, String srcurl, FramePath curpath, List<FramePath> buf) { if (log.isDebugEnabled()) { log.debug("Checking frame url: " + wdriver.getCurrentUrl() + " against " + srcurl); } String cururl = wdriver.getCurrentUrl(); if (srcurl == null || cururl.equals(srcurl)) { curpath.appendUrl(cururl); buf.add(curpath); } List<WebElement> frames = FrameUtils.getChildFrames(wdriver); for (WebElement frame : frames) { try { FramePath nFramePath = new FramePath(curpath); nFramePath.appendFrame(frame); wdriver.switchTo().frame(frame); findFramePaths(wdriver, srcurl, nFramePath, buf); FrameUtils.traverseFramePath(wdriver, curpath); } catch (StaleElementReferenceException e) { if (log.isErrorEnabled()) { log.error("A frame could not be switched to, skipping.", e); } } catch (NoSuchFrameException e) { if (log.isErrorEnabled()) { log.error("A frame could not be switched to, skipping.", e); } } } }
From source file:edu.umd.cs.guitar.replayer2.WebReplayerMonitor2.java
License:Open Source License
/** * Get component using their GUI identification properties * <p>// www. j a va 2 s . co m * * @return the component if found and null if not found */ @Override public GComponent getComponent(GApplication application, ComponentType window, ComponentType component) { if (!(application instanceof WebApplication)) throw new ReplayerConstructionException(); WebApplication webApplication = (WebApplication) application; WebDriver driver = webApplication.getDriver(); String xpathExpression = getXpathFromComponent(component); GUITARLog.log.debug("xPath Expression: " + xpathExpression); String currentHandler = driver.getWindowHandle(); driver.manage().timeouts().implicitlyWait(2000, TimeUnit.MILLISECONDS); // Scan all open window for the desired element for (String windowHandler : driver.getWindowHandles()) { try { driver.switchTo().window(windowHandler); if (isSearchWithinWindow) { ComponentType windowComponent = window; ComponentTypeWrapper windowComponentWrapper = new ComponentTypeWrapper(windowComponent); String windowTitle = windowComponentWrapper.getFirstValueByName(GUITARConstants.TITLE_TAG_NAME); windowTitle = normalizeURL(windowTitle); String url = driver.getCurrentUrl(); url = normalizeURL(url); if (!windowTitle.equals(url)) { continue; } } WebElement element = driver.findElement(By.xpath(xpathExpression)); GComponent webComponent = new WebComponent(element, null, null, null); GUITARLog.log.debug("Elemement FOUND in: " + driver.getCurrentUrl()); return webComponent; } catch (org.openqa.selenium.NoSuchElementException e) { GUITARLog.log.debug("Elemement NOT found in: " + driver.getCurrentUrl()); } } driver.switchTo().window(currentHandler); return null; }
From source file:edu.umd.cs.guitar.ripper.WebRipperMonitor.java
License:Open Source License
private String parseUrl(String href) { String finalURL = ""; ///*from ww w .j a v a2 s . c o m*/ if (href.startsWith("http://") || href.startsWith("https://")) { finalURL = href; } else { // Must not be a full url WebDriver driver = application.getDriver(); String current = driver.getCurrentUrl(); if (href.startsWith("/")) { // Link is a direct reference from root // 7 = "http://".length int third = 7 + current.substring(7).indexOf('/'); finalURL = current.substring(0, third) + href; } else { // Not from root String end = current.substring(0, current.lastIndexOf('/') + 1); finalURL = end + href; } } return finalURL; }
From source file:edu.usc.cs.ir.htmlunit.handler.Arguntrader.java
License:Apache License
public String processDriver(final WebDriver driver) { boolean check = false; try {//from w ww . ja va2s . c o m WebElement e = driver.findElement(By.id("username")); check = true; } catch (Exception e) { System.out.println("No Login Form detected"); } if (check) { WebElement username = driver.findElement(By.id("username")); WebElement password = driver.findElement(By.id("password")); username.sendKeys("username"); password.sendKeys("password"); driver.findElement(By.className("button1")).click(); (new WebDriverWait(driver, 8)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } return d.getCurrentUrl().toLowerCase().contains(driver.getCurrentUrl().toLowerCase()); } }); } return driver.getPageSource().replaceAll("&", "&"); }
From source file:edu.usc.cs.ir.htmlunit.handler.Sturmgewehr.java
License:Apache License
public String processDriver(WebDriver driver) { StringBuffer buffer = new StringBuffer(); WebElement posts = driver.findElement(By.xpath("//div[@class='ipsBox']//ol")); buffer.append((String) ((JavascriptExecutor) driver).executeScript("return arguments[0].innerHTML;", posts)) .append("\n\n"); int lastPage = Integer.parseInt( driver.findElement(By.xpath("//li[@class='ipsPagination_last']//a")).getAttribute("data-page")); for (int i = 2; i <= lastPage; i++) buffer.append("<a href=\"").append(driver.getCurrentUrl()).append("&page=").append(i).append("\" />\n"); return buffer.toString(); }
From source file:edu.usc.cs.ir.selenium.handler.Arguntrader.java
License:Apache License
public String processDriver(final WebDriver driver) { boolean check = false; try {//www . ja v a2 s . c o m WebElement e = driver.findElement(By.id("username")); check = true; } catch (Exception e) { System.out.println("No Login Form detected"); } if (check) { WebElement username = driver.findElement(By.id("username")); WebElement password = driver.findElement(By.id("password")); username.sendKeys("username"); password.sendKeys("password"); driver.findElement(By.className("button1")).click(); (new WebDriverWait(driver, 8)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } return d.getCurrentUrl().toLowerCase().contains(driver.getCurrentUrl().toLowerCase()); } }); } //System.out.println(); return driver.getPageSource().replaceAll("&", "&"); }
From source file:edu.usc.cs.ir.selenium.handler.Glocktalk.java
License:Apache License
public String processDriver(WebDriver driver) { StringBuffer buffer = new StringBuffer(); // Extract content - getText doesn't return any links String content = driver.findElement(By.tagName("body")).getText(); buffer.append(content).append("\n"); // Extract threads from a forum through all of its navigation if (driver.getCurrentUrl().startsWith("http://www.glocktalk.com/forum")) { // Extract the last page number List<WebElement> pages = driver.findElements(By.xpath("//div[@class='PageNav']//nav//a[@class='']")); buffer.append(getThreadsFromForum(driver)).append("\n"); if (pages != null && !pages.isEmpty()) { WebElement currentPage = driver .findElement(By.xpath("//div[@class='PageNav']//nav//a[@class='currentPage ']")); Integer currentPageNo = Integer.parseInt(currentPage.getText()); if (currentPageNo % PAGE_FETCH_LIMIT == 1) { Integer lastPage = Integer.parseInt(pages.get(pages.size() - 1).getText()); String currentUrl = driver.getCurrentUrl().substring(0, driver.getCurrentUrl().lastIndexOf("/") + 1); int i = currentPageNo + 1; for (; i < (currentPageNo + PAGE_FETCH_LIMIT) && i <= lastPage; i++) { try { driver.get(currentUrl + "page-" + i); } catch (TimeoutException e) { System.out.println("Timeout Exception for page = " + i); } finally { buffer.append(getThreadsFromForum(driver)).append("\n"); }//from w w w. j av a2 s .c om } if (i <= lastPage) buffer.append("<a href=\"").append(currentUrl + "page-" + i).append("\" />").append("\n"); } } } // Extract all links from a thread else if (driver.getCurrentUrl().startsWith("http://www.glocktalk.com/threads")) { // Extract the last page number List<WebElement> pages = driver.findElements(By.xpath("//div[@class='PageNav']//nav//a[@class='']")); buffer.append(getPostsFromThread(driver)).append("\n"); if (pages != null && !pages.isEmpty()) { WebElement currentPage = driver .findElement(By.xpath("//div[@class='PageNav']//nav//a[@class='currentPage ']")); Integer currentPageNo = Integer.parseInt(currentPage.getText()); if (currentPageNo % PAGE_FETCH_LIMIT == 1) { Integer lastPage = Integer.parseInt(pages.get(pages.size() - 1).getText()); String currentUrl = driver.getCurrentUrl().substring(0, driver.getCurrentUrl().lastIndexOf("/") + 1); int i = currentPageNo + 1; for (; i < (currentPageNo + PAGE_FETCH_LIMIT) && i <= lastPage; i++) { try { driver.get(currentUrl + "page-" + i); } catch (TimeoutException e) { System.out.println("Timeout Exception for page = " + i); } finally { buffer.append(getPostsFromThread(driver)).append("\n"); } } if (i <= lastPage) buffer.append("<a href=\"").append(currentUrl + "page-" + i).append("\" />").append("\n"); } } } // Extract User Images else if (driver.getCurrentUrl().startsWith("http://www.glocktalk.com/members")) { List<WebElement> srcLinks = driver.findElements(By.xpath("//div[@class='profilePage']//*[@src]")); Set<String> images = new HashSet<String>(); for (WebElement link : srcLinks) { String linkValue = null; if (!link.getTagName().equals("img")) continue; linkValue = link.getAttribute("src"); System.out.println(linkValue); images.add("<img src=\"" + linkValue + "\" />"); } buffer.append(images); } // Extract Media - Images else if (driver.getCurrentUrl().startsWith("http://www.glocktalk.com/media")) { // Extract the last page number List<WebElement> pages = driver.findElements(By.xpath("//div[@class='PageNav']//nav//a[@class='']")); buffer.append(getImagesFromMedia(driver)).append("\n"); if (pages != null && !pages.isEmpty()) { WebElement currentPage = driver .findElement(By.xpath("//div[@class='PageNav']//nav//a[@class='currentPage ']")); Integer currentPageNo = Integer.parseInt(currentPage.getText()); if (currentPageNo % PAGE_FETCH_LIMIT == 1) { Integer lastPage = Integer.parseInt(pages.get(pages.size() - 1).getText()); String currentUrl = driver.getCurrentUrl().substring(0, driver.getCurrentUrl().lastIndexOf("/")); int i = currentPageNo + 1; for (; i < (currentPageNo + PAGE_FETCH_LIMIT) && i <= lastPage; i++) { try { driver.get(currentUrl + "?page=" + i); } catch (TimeoutException e) { System.out.println("Timeout Exception for page = " + i); } finally { buffer.append(getImagesFromMedia(driver)).append("\n"); } } if (i <= lastPage) buffer.append("<a href=\"").append(currentUrl + "?page=" + i).append("\" />").append("\n"); } } } //System.out.println(); return buffer.toString(); }