List of usage examples for org.openqa.selenium WebElement getAttribute
String getAttribute(String name);
From source file:com.github.swt_release_fetcher.Main.java
License:Apache License
public static void main(String[] args) throws Exception { for (String arg : args) { if (arg.equals("--deploy")) { deployArtifacts = true;//from w w w .j a va 2 s . c o m } if (arg.equals("--help")) { showHelp(); } if (arg.equals("--debug")) { debug = true; } if (arg.equals("--silent")) { silentMode = true; } } // the mirror we use for all following downloads String mirrorUrl = ""; // lightweight headless browser WebDriver driver = new HtmlUnitDriver(); // determine if the website has changed since our last visit // stop if no change was detected // Ignore this check if we just want to deploy if (!deployArtifacts) { SwtWebsite sw = new SwtWebsite(); try { if (!sw.hasChanged(driver, WEBSITE_URL)) { // exit if no change was detected printSilent("SWT website hasn't changed since our last visit. Stopping here."); driver.quit(); System.exit(0); } else { // proceed if the site has changed System.out .println("Page change detected! You may want to run the script in deploy mode again."); } } catch (IOException ioe) { System.out.println(ioe.getMessage()); } } // get SWT's main site printDebug("Parsing eclipse.org/swt to find a mirror"); driver.get(WEBSITE_URL); printDebug(WEBSITE_URL); // find the stable release branch link and hit it final List<WebElement> elements = driver.findElements(By.linkText("Linux")); final String deeplink = elements.get(0).getAttribute("href"); printDebug("deeplink: " + deeplink); driver.get(deeplink); // get the direct download link from the next page final WebElement directDownloadLink = driver.findElement(By.linkText("Direct link to file")); printDebug("direct download link: " + directDownloadLink.getAttribute("href")); // the direct link again redirects, here is our final download link! driver.get(directDownloadLink.getAttribute("href")); final String finalDownloadLink = driver.getCurrentUrl(); printDebug("final download link: " + finalDownloadLink); // Close the browser driver.quit(); // extract the mirror URL for all following downloads String[] foo = finalDownloadLink.split("\\/", 0); final String filename = foo[foo.length - 1]; mirrorUrl = (String) finalDownloadLink.subSequence(0, finalDownloadLink.length() - filename.length()); // debug output printDebug("full download url: " + finalDownloadLink); printDebug("mirror url: " + mirrorUrl); // determine current release name String[] releaseName = filename.split("-gtk-linux-x86.zip"); String versionName = releaseName[0].split("-")[1]; System.out.println("current swt version: " + versionName); // TODO move to properties file PackageInfo[] packages = { // Win32 new PackageInfo("win32-win32-x86.zip", "org.eclipse.swt.win32.win32.x86"), new PackageInfo("win32-win32-x86_64.zip", "org.eclipse.swt.win32.win32.x86_64"), // Linux new PackageInfo("gtk-linux-ppc.zip", "org.eclipse.swt.gtk.linux.ppc"), new PackageInfo("gtk-linux-ppc64.zip", "org.eclipse.swt.gtk.linux.ppc64"), new PackageInfo("gtk-linux-x86.zip", "org.eclipse.swt.gtk.linux.x86"), new PackageInfo("gtk-linux-x86_64.zip", "org.eclipse.swt.gtk.linux.x86_64"), new PackageInfo("gtk-linux-s390.zip", "org.eclipse.swt.gtk.linux.s390"), new PackageInfo("gtk-linux-s390x.zip", "org.eclipse.swt.gtk.linux.s390x"), // OSX new PackageInfo("cocoa-macosx.zip", "org.eclipse.swt.cocoa.macosx"), new PackageInfo("cocoa-macosx-x86_64.zip", "org.eclipse.swt.cocoa.macosx.x86_64"), // Additional platforms new PackageInfo("gtk-aix-ppc.zip", "org.eclipse.swt.gtk.aix.ppc"), new PackageInfo("gtk-aix-ppc64.zip", "org.eclipse.swt.gtk.aix.ppc64"), new PackageInfo("gtk-hpux-ia64.zip", "org.eclipse.swt.gtk.hpux.ia64"), new PackageInfo("gtk-solaris-sparc.zip", "org.eclipse.swt.gtk.solaris.sparc"), new PackageInfo("gtk-solaris-x86.zip", "org.eclipse.swt.gtk.solaris.x86") }; File downloadDir = new File("downloads"); if (!downloadDir.exists()) { downloadDir.mkdirs(); } for (PackageInfo pkg : packages) { final String zipFileName = releaseName[0] + "-" + pkg.zipName; final URL downloadUrl = new URL(mirrorUrl + zipFileName); final URL checksumUrl = new URL(mirrorUrl + "checksum/" + zipFileName + ".md5"); System.out.print("* Downloading " + pkg.zipName + " ... "); Artifact artifact = new Artifact(new File(downloadDir, zipFileName), versionName, pkg.artifactId); artifact.downloadAndValidate(downloadUrl, checksumUrl); if (deployArtifacts) { artifact.deploy(); } } }
From source file:com.github.wiselenium.elements.component.impl.MultiSelectImpl.java
License:Open Source License
@Override public List<String> getSelectedValues() { List<String> values = Lists.newArrayList(); List<WebElement> selectedOptions = this.getWrappedSelect().getAllSelectedOptions(); for (WebElement option : selectedOptions) values.add(option.getAttribute("value")); return values; }
From source file:com.google.appengine.tck.env.appspot.AppspotLoginHandler.java
License:Open Source License
public void login(WebDriver driver, LoginContext context) { try {/*from w ww .j a v a 2 s . c o m*/ WebElement email = driver.findElement(By.id("Email")); if (email.getAttribute("readonly") == null) { email.clear(); email.sendKeys(context.getEmail()); } WebElement password = driver.findElement(By.id("Passwd")); password.sendKeys(context.getPassword()); driver.findElement(By.name("signIn")).click(); } catch (NoSuchElementException e) { throw new IllegalStateException( String.format("URL[%s]\n\n%s", driver.getCurrentUrl(), driver.getPageSource()), e); } }
From source file:com.google.caja.plugin.BrowserTestCase.java
License:Apache License
protected static String renderElements(List<WebElement> elements) { StringBuilder sb = new StringBuilder(); sb.append('['); for (int i = 0, n = elements.size(); i < n; i++) { if (i != 0) { sb.append(", "); }//from ww w. j a va 2s. c o m WebElement el = elements.get(i); sb.append('<').append(el.getTagName()); String id = el.getAttribute("id"); if (id != null) { sb.append(" id=\""); Escaping.escapeXml(id, false, sb); sb.append('"'); } String className = el.getAttribute("class"); if (className != null) { sb.append(" class=\""); Escaping.escapeXml(className, false, sb); sb.append('"'); } sb.append('>'); } sb.append(']'); return sb.toString(); }
From source file:com.googlecode.fightinglayoutbugs.DetectInvalidImageUrls.java
License:Apache License
private void checkVisibleImgElements() { int numImgElementsWithoutSrcAttribute = 0; int numImgElementsWithEmptySrcAttribute = 0; final Set<String> seen = new HashSet<String>(); for (WebElement img : _webPage.findElements(By.tagName("img"))) { if (img.isDisplayed()) { final String src = img.getAttribute("src"); if (src == null) { ++numImgElementsWithoutSrcAttribute; } else if ("".equals(src)) { ++numImgElementsWithEmptySrcAttribute; } else { if (seen.add(src)) { try { checkImageUrl(src, "Detected visible <img> element with invalid src attribute \"" + src + "\""); } catch (MalformedURLException e) { addLayoutBugIfNotPresent("Detected visible <img> element with invalid src attribute \"" + src + "\" -- " + e.getMessage()); }//from w w w.j a v a 2 s. c o m } } } } if (numImgElementsWithEmptySrcAttribute > 0) { if (numImgElementsWithEmptySrcAttribute == 1) { addLayoutBugIfNotPresent("Detected visible <img> element with empty src attribute."); } else { addLayoutBugIfNotPresent("Detected " + numImgElementsWithEmptySrcAttribute + " visible <img> elements with empty src attribute."); } } if (numImgElementsWithoutSrcAttribute > 0) { if (numImgElementsWithEmptySrcAttribute == 1) { addLayoutBugIfNotPresent("Detected visible <img> without src attribute."); } else { addLayoutBugIfNotPresent("Detected " + numImgElementsWithoutSrcAttribute + " visible <img> elements without src attribute."); } } }
From source file:com.googlecode.fightinglayoutbugs.DetectInvalidImageUrls.java
License:Apache License
private void checkStyleAttributes() { for (WebElement element : _webPage.findElements(By.xpath("//*[@style]"))) { final String css = element.getAttribute("style"); for (String importUrl : getImportUrlsFrom(css)) { checkCssResourceAsync(// w ww . j ava 2 s. c o m importUrl + " (imported in style attribute of <" + element.getTagName() + "> element)", importUrl, _baseUrl, _documentCharset); } for (String url : extractUrlsFrom(css)) { try { checkImageUrl(url, "Detected <" + element.getTagName() + "> element with invalid image URL \"" + url + "\" in its style attribute"); } catch (MalformedURLException e) { addLayoutBugIfNotPresent( "Detected <" + element.getTagName() + "> element with invalid image URL \"" + url + "\" in its style attribute -- " + e.getMessage()); } } } }
From source file:com.googlecode.fightinglayoutbugs.DetectInvalidImageUrls.java
License:Apache License
private void checkLinkedCss() { for (WebElement link : _webPage.findElements(By.tagName("link"))) { String rel = link.getAttribute("rel"); if (rel != null) { rel = rel.toLowerCase(Locale.ENGLISH); }/*from ww w . j a va 2 s.c om*/ final String type = link.getAttribute("type"); final String href = link.getAttribute("href"); if ((rel != null && rel.contains("stylesheet")) || (type != null && type.startsWith("text/css"))) { if (href != null) { String charset = link.getAttribute("charset"); if (!isValidCharset(charset)) { charset = _documentCharset; } checkCssResourceAsync(href, href, _baseUrl, charset); } } // prepare checkFavicon ... if (rel != null && ("icon".equals(rel) || "shortcut icon".equals(rel))) { if (href != null) { _faviconUrl = href; } } } }
From source file:com.googlecode.ounit.selenium.CssHelper.java
License:Open Source License
public static boolean hasStyleAttribute(WebElement e) { String st = e.getAttribute("style"); if (st == null || "".equals(st)) return false; else//ww w .ja va 2 s . c o m return true; }
From source file:com.googlesites.LoginPage.java
public void typeEmail(String email) { WebElement emailEl = driver.findElement(By.id("Email")); driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); if (emailEl.getAttribute("value") != null) { emailEl.clear();// w ww . jav a 2 s . co m } emailEl.sendKeys(email); driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); String actualSetEmail = emailEl.getAttribute("value"); if (!actualSetEmail.equals(email)) { typeEmail(email); } }
From source file:com.googlesites.LoginPage.java
public void typePassword(String password) { WebElement pass = driver.findElement(By.id("Passwd")); driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); if (pass.getAttribute("value") != null) { pass.clear();/*ww w . ja va 2 s. co m*/ } pass.sendKeys(password); driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); String actualSetPassword = pass.getAttribute("value"); if (!actualSetPassword.equals(password)) { typePassword(password); } }