congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
WebElement.getAttribute
Code IndexAdd Tabnine to your IDE (free)

How to use
getAttribute
method
in
org.openqa.selenium.WebElement

Best Java code snippets using org.openqa.selenium.WebElement.getAttribute (Showing top 20 results out of 1,503)

origin: selenide/selenide

private static String getAttributeValue(WebElement element, String attributeName) {
 String attr = element.getAttribute(attributeName);
 return attr == null ? "" : attr;
}
origin: selenide/selenide

@Override
public boolean apply(Driver driver, WebElement element) {
 return element.getAttribute(attributeName) != null;
}
origin: selenide/selenide

@Override
public boolean apply(Driver driver, WebElement element) {
 String classes = element.getAttribute("class");
 return classes != null && contains(classes.split(" "), cssClass);
}
origin: selenide/selenide

 @Override
 public String execute(SelenideElement proxy, WebElementSource locator, Object[] args) {
  return locator.getWebElement().getAttribute((String) args[0]);
 }
}
origin: selenide/selenide

 @Override
 public String execute(SelenideElement proxy, WebElementSource selectElement, Object[] args) throws IOException {
  WebElement option = getSelectedOption.execute(proxy, selectElement, args);
  return option == null ? null : option.getAttribute("value");
 }
}
origin: selenide/selenide

 @Override
 public String execute(SelenideElement proxy, WebElementSource locator, Object[] args) {
  return locator.getWebElement().getAttribute("data-" + args[0]);
 }
}
origin: selenide/selenide

 @Override
 public String execute(SelenideElement proxy, WebElementSource locator, Object[] args) {
  return locator.getWebElement().getAttribute("value");
 }
}
origin: selenide/selenide

 @Override
 public String execute(SelenideElement proxy, WebElementSource locator, Object[] args) {
  return locator.getWebElement().getAttribute("name");
 }
}
origin: selenide/selenide

private Describe attr(String attributeName) {
 String attributeValue = element.getAttribute(attributeName);
 return attr(attributeName, attributeValue);
}
origin: selenide/selenide

public File download(Driver driver, WebElement element, long timeout) throws IOException {
 String fileToDownloadLocation = element.getAttribute("href");
 if (fileToDownloadLocation == null || fileToDownloadLocation.trim().isEmpty()) {
  throw new IllegalArgumentException("The element does not have href attribute: " + describe(driver, element));
 }
 return download(driver, fileToDownloadLocation, timeout);
}
origin: galenframework/galen

@Override
public String getText() {
  WebElement webElement = getWebElement();
  if ("input".equals(webElement.getTagName().toLowerCase())) {
    String value = webElement.getAttribute("value");
    if (value == null) {
      value = "";
    }
    
    return value;
  }
  else return getWebElement().getText().trim();
}
origin: selenide/selenide

 @Override
 public String execute(SelenideElement proxy, WebElementSource locator, Object[] args) {
  WebElement element = locator.getWebElement();
  if (locator.driver().browser().isIE()) {
   return element.getAttribute("innerText");
  }
  return element.getAttribute("textContent");
 }
}
origin: selenide/selenide

public SelenideElement getSelectedRadio(By radioField) {
 for (WebElement radio : $$(radioField)) {
  if (radio.getAttribute("checked") != null) {
   return $(radio);
  }
 }
 return null;
}
origin: spring-io/initializr

public WebElement dependency(String value) {
  for (WebElement element : this.form.findElements(By.name("style"))) {
    if (value.equals(element.getAttribute("value"))) {
      return element;
    }
  }
  throw new AssertionError("Dependency not found: " + value);
}
origin: cloudfoundry/uaa

@Test
public void testBuildInfo() throws Exception {
  webDriver.get(baseUrl + "/login");
  String regex = "Version: \\S+, Commit: \\w{7}, Timestamp: .+, UAA: " + baseUrl;
  assertTrue(webDriver.findElement(By.cssSelector(".footer .copyright")).getAttribute("title").matches(regex));
}
origin: cloudfoundry/uaa

@Test
public void testAutocompleteIsDisabledForPasswordField() {
  webDriver.get(baseUrl + "/login");
  WebElement password = webDriver.findElement(By.name("password"));
  assertEquals("off", password.getAttribute("autocomplete"));
}
origin: cloudfoundry/uaa

@Test
public void testQRCodeScreen() throws Exception {
  performLogin(username);
  assertEquals(zoneUrl + "/login/mfa/register", webDriver.getCurrentUrl());
  String imageSrc = webDriver.findElement(By.id("qr")).getAttribute("src");
  String secretKey = getSecretFromQrImageString(imageSrc);
  webDriver.findElement(By.id("Next")).click();
  verifyCodeOnRegistration(secretKey, "/");
}
origin: selenide/selenide

 @Override
 public String execute(SelenideElement proxy, WebElementSource locator, Object[] args) {
  WebElement element = locator.getWebElement();
  if (locator.driver().browser().isHtmlUnit()) {
   return locator.driver().executeJavaScript("return arguments[0].innerHTML", element);
  }
  return element.getAttribute("innerHTML");
 }
}
origin: cloudfoundry/uaa

@Test
public void testQRCodeScreen_ClickManualAndReturn() throws Exception{
  performLogin(username);
  assertEquals(zoneUrl + "/login/mfa/register", webDriver.getCurrentUrl());
  webDriver.findElement(By.linkText("manual setup instructions")).click();
  assertEquals(zoneUrl + "/login/mfa/manual", webDriver.getCurrentUrl());
  webDriver.findElement(By.id("Back")).click();
  assertEquals(zoneUrl + "/login/mfa/register", webDriver.getCurrentUrl());
  String imageSrc = webDriver.findElement(By.id("qr")).getAttribute("src");
  String secretKey = getSecretFromQrImageString(imageSrc);
  webDriver.findElement(By.id("Next")).click();
  verifyCodeOnRegistration(secretKey, "/");
}
origin: cloudfoundry/uaa

@Test
public void testLoginReloadRetainsFormRedirect() {
  String redirectUri = "http://expected.com";
  webDriver.get(baseUrl + "/oauth/authorize?client_id=test&redirect_uri="+redirectUri);
  ((JavascriptExecutor)webDriver).executeScript("document.getElementsByName('X-Uaa-Csrf')[0].value=''");
  webDriver.manage().deleteCookieNamed("JSESSIONID");
  webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
  assertThat(webDriver.getCurrentUrl(), Matchers.containsString("/login"));
  assertThat(webDriver.findElement(By.name("form_redirect_uri")).getAttribute("value"), Matchers.containsString("redirect_uri="+redirectUri));
}
org.openqa.seleniumWebElementgetAttribute

Javadoc

Get the value of the given attribute of the element. Will return the current value, even if this has been modified after the page has been loaded.

More exactly, this method will return the value of the property with the given name, if it exists. If it does not, then the value of the attribute with the given name is returned. If neither exists, null is returned.

The "style" attribute is converted as best can be to a text representation with a trailing semi-colon.

The following are deemed to be "boolean" attributes, and will return either "true" or null:

async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked, defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking, selected, truespeed, willvalidate

Finally, the following commonly mis-capitalized attribute/property names are evaluated as expected:

  • If the given name is "class", the "className" property is returned.
  • If the given name is "readonly", the "readOnly" property is returned.
Note: The reason for this behavior is that users frequently confuse attributes and properties. If you need to do something more precise, e.g., refer to an attribute even when a property of the same name exists, then you should evaluate Javascript to obtain the result you desire.

Popular methods of WebElement

  • getText
    Get the visible (i.e. not hidden by CSS) text of this element, including sub-elements.
  • click
    Click this element. If this causes a new page to load, you should discard all references to this ele
  • sendKeys
    Use this method to simulate typing into an element, which may set its value.
  • clear
    If this element is a text entry element, this will clear the value. Has no effect on other elements.
  • isDisplayed
    Is this element displayed or not? This method avoids the problem of having to parse an element's "st
  • findElements
    Find all elements within the current context using the given mechanism. When using xpath be aware th
  • isSelected
    Determine whether or not this element is selected or not. This operation only applies to input eleme
  • findElement
    Find the first WebElement using the given method. See the note in #findElements(By) about finding vi
  • getTagName
    Get the tag name of this element. Not the value of the name attribute: will return"input" for the el
  • isEnabled
    Is the element currently enabled or not? This will generally return true for everything but disabled
  • getLocation
    Where on the page is the top left-hand corner of the rendered element?
  • submit
    If this current element is a form, or an element within a form, then this will be submitted to the r
  • getLocation,
  • submit,
  • getSize,
  • getCssValue,
  • getRect,
  • getScreenshotAs,
  • getValue,
  • setSelected,
  • toggle

Popular in Java

  • Reading from database using SQL prepared statement
  • startActivity (Activity)
  • setContentView (Activity)
  • putExtra (Intent)
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now