List of usage examples for org.openqa.selenium WebElement getTagName
String getTagName();
From source file:edu.uga.cs.clickminer.datamodel.log.ElementEntry.java
License:Open Source License
/** * <p>Constructor for ElementEntry.</p> * * @param wdriver a {@link org.openqa.selenium.WebDriver} object. * @param elem a {@link org.openqa.selenium.WebElement} object. *//*from w w w.ja v a 2s . c o m*/ public ElementEntry(WebDriver wdriver, WebElement elem) { super(null); tag = elem.getTagName(); name = elem.getAttribute("name"); id = elem.getAttribute("id"); try { locator = JSUtils.getElementLocator(wdriver, elem); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Unable to get element locator for tag " + tag + ". Setting empty locator.", e); } locator = new ElementLocator(); } }
From source file:edu.uga.cs.clickminer.datamodel.log.ElementEntry.java
License:Open Source License
/** * <p>matches.</p>/*from w w w. j a v a 2 s .c om*/ * * @param elem a {@link org.openqa.selenium.WebElement} object. */ public boolean matches(WebElement elem) { String elemname = elem.getAttribute("name"); String elemid = elem.getAttribute("id"); if (tag.equals(elem.getTagName())) { if ((name == null && elemname == name) || name.equals(elemname)) { if ((id == null && elemid == id) || id.equals(elemid)) { return true; } } } return false; }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_11.</p> *//*from www.j av a 2s. co m*/ public static void browserEngineTest_11() { FirefoxProfile profile = new FirefoxProfile( TestUtils.getWebdriverProfile("/home/cjneasbi/.mozilla/firefox", "webdriver")); WebDriver wdriver = new FirefoxDriver(null, profile, TestUtils.createProxyConfig()); //ProxyClient pc = new ProxyClient("127.0.0.1", 8888); //BrowserEngine bengine = new BrowserEngine(pc, wdriver); wdriver.get("http://cnn-f.akamaihd.net/crossdomain.xml"); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } List<WebElement> sresult = wdriver.findElements(By.xpath("//*")); for (WebElement elem : sresult) { System.out.println(elem.getTagName()); } }
From source file:edu.uga.cs.clickminer.util.FlashUtils.java
License:Open Source License
/** * Parses the flash vars./*from w ww . jav a 2 s . c o m*/ * * @param elem * the elem * @return the map */ private static Map<String, String> parseFlashVars(WebElement elem) { Map<String, String> retval = new HashMap<String, String>(); String flashVarStr = null; if (elem.getTagName().toLowerCase().equals("embed")) { flashVarStr = elem.getAttribute("FlashVars"); } else if (elem.getTagName().toLowerCase().equals("object")) { flashVarStr = elem.getAttribute("flashvars"); if (flashVarStr != null) { try { WebElement param = elem.findElement(By.xpath("child::param[@name='FlashVars']")); flashVarStr = param.getAttribute("value"); } catch (NoSuchElementException e) { flashVarStr = null; } } } if (flashVarStr != null) { try { String[] varparts = flashVarStr.split("&"); for (String vartup : varparts) { String[] tupparts = vartup.split("="); String value = ""; if (tupparts.length > 1) { value = URLDecoder.decode(tupparts[1], "UTF-8"); } retval.put(URLDecoder.decode(tupparts[0], "UTF-8"), value); } } catch (UnsupportedEncodingException e) { if (log.isErrorEnabled()) { log.error("", e); } retval.clear(); } } return retval; }
From source file:edu.umd.cs.guitar.model.WebComponent.java
License:Open Source License
public WebComponent(WebElement el, WebComponent parent, String xpath, GWindow window) { super(window); element = el;/*w w w .j a v a 2 s . c om*/ this.parent = parent; this.title = el.getTagName(); this.xpath = xpath; }
From source file:edu.umd.cs.guitar.model.WebDefaultHashcodeGenerator2.java
License:Open Source License
@Override public long generateHashCode(GComponent gComponent) { if (!(gComponent instanceof WebComponent)) { return 0; }/*from w w w . j a va 2 s. com*/ WebComponent webComponent = (WebComponent) gComponent; WebElement element = webComponent.getElement(); if (element == null) { return 0; } HashCodeBuilder hashcodeBuilder = new HashCodeBuilder(); // Tag hashcodeBuilder.append(element.getTagName()); if (isIncludedText()) { hashcodeBuilder.append(element.getText()); } // ID attributes for (String attributeName : WebConstants.ID_ATTRIBUTE_LIST) { String attributeValue = element.getAttribute(attributeName); if (attributeValue != null && !("".equals(attributeName.trim()))) { hashcodeBuilder.append(attributeName); hashcodeBuilder.append(attributeValue); } } return Math.abs(hashcodeBuilder.toHashCode()); }
From source file:edu.usc.cs.ir.selenium.handler.Glocktalk.java
License:Apache License
private Set<String> getPostsFromThread(WebDriver driver) { List<WebElement> links = driver.findElements(By.xpath("//ol[@id='messageList']//*[@href|@src]")); Set<String> filteredLinks = new HashSet<String>(); for (WebElement link : links) { String linkValue = null;// w ww.ja v a 2s . c o m if (link.getAttribute("src") != null && !link.getTagName().equals("img")) continue; if (link.getAttribute("src") != null) linkValue = link.getAttribute("src"); else linkValue = link.getAttribute("href"); if (linkValue.startsWith("http://www.glocktalk.com/account") || linkValue.startsWith("http://www.glocktalk.com/misc") || linkValue.startsWith("http://www.glocktalk.com/goto") || linkValue.startsWith("http://www.glocktalk.com/social-forums") || linkValue.startsWith("http://www.glocktalk.com/search") || linkValue.contains("#")) continue; //System.out.println(linkValue); filteredLinks.add("<a href=\"" + linkValue + "\" />"); } return filteredLinks; }
From source file:edu.usc.cs.ir.selenium.handler.Glocktalk.java
License:Apache License
private Set<String> getImagesFromMedia(WebDriver driver) { List<WebElement> srcLinks = driver.findElements( By.xpath("//div[@class='gridSection gridGroup LightboxContainer LightboxLoadable']//*[@src]")); Set<String> images = new HashSet<String>(); for (WebElement link : srcLinks) { String linkValue = null;/*from ww w . j a v a2 s .c o m*/ if (!link.getTagName().equals("img")) continue; linkValue = link.getAttribute("src"); System.out.println(linkValue); images.add("<img src=\"" + linkValue + "\" />"); } return images; }
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 ww w. j a v a 2 s . c o m } 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(); }
From source file:endtoend.selectors.mixed.MixedSelectorsTest.java
License:Apache License
private void assertElementDetails(WebElement element, String tagName, String idAttribute, String classAttribute) {/* ww w . jav a 2 s . c o m*/ assertThat(element.getTagName(), is(tagName)); assertThat(element.getAttribute("id"), is(idAttribute)); if (classAttribute == null) { assertThat(element.getAttribute("class"), is(nullValue())); } else { assertThat(element.getAttribute("class"), is(classAttribute)); } }