title: Get Attributes of a Hidden Element
body: <p>I have a table I am trying to test. Inside one of the columns is yes/no radio buttons which when the page is rendered is hidden underneath an image so that there is a check-mark or an X when yes or no is selected. </p>
  
  <p>The attribute for the radio button when yes is selected <code>checked="true"</code>. </p>
  
  <p>How do I with <code>Selenium2</code> get that attribute so that I can compare it or make assertions against it?</p>
  
  <p>I have tried the following, which simply results in a null pointer error. </p>
  
  <pre><code>private void verifyPOEligibleYesNull(String driverName)
  {
      int min = 1;
      int max = 6;
      JavascriptExecutor js = (JavascriptExecutor)driver;
      StringBuilder stringBuilder = new StringBuilder();
      //Navigate to System Facing
      driver = browser.getDriver(driverName);
      driver.manage().window().maximize();
      driver.navigate().to("http://theURL");
  
      //Enter userName
      WebElement userName = driver.findElement(By.id("username"));
      userName.clear();
      userName.sendKeys(user);
  
      //Enter Password
      WebElement password = driver.findElement(By.id("pword"));
      password.clear();
      password.sendKeys(pwd);
  
      //Click Login
      WebElement loginBtn = driver.findElement(By.xpath("/html/body/div/div/form/div[3]/div/input"));
      loginBtn.click();
      try 
      {
          Thread.sleep(5000);
      } 
      catch (InterruptedException e) 
      {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      WebElement ivToPoBtn = driver.findElement(By.xpath("/html/body/div/div/div/ul/li/a/img"));
      ivToPoBtn.click();
      try 
      {
          Thread.sleep(5000);
      } 
      catch (InterruptedException e) 
      {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      //Grab a random row and determine whether the PO Eligible is "Yes"
      String rowNum = Integer.toString(rand.nextInt(max - min + 1) + min);
      WebElement randomRow = driver.findElement(By.xpath("/html/body/div/div/div/div/form/div/div[2]/div/div[2]/div/div/div/div/div/div/div/table/tbody/tr["+rowNum+"]/td/div/div/input")); 
      String poEligibleChecked = randomRow.getAttribute("checked").toString();
      stringBuilder.append("var x = $(\""+poEligibleChecked+"\");");
      stringBuilder.append("return x.toString();");
      String res  = (String) js.executeScript(stringBuilder.toString());
      System.out.println(res);    
  }
  </code></pre>
  
  <p>I have even tried the following which was suggested from <a href="http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions#Q%3a_Why_is_it_not_possible_to_interact_with_hidden_elements?" rel="nofollow">WebDriver FAQ</a>:</p>
  
  <pre><code>    WebElement randomRow = driver.findElement(By.xpath("/html/body/div/div/div/div/form/div/div[2]/div/div[2]/div/div/div/div/div/div/div/table/tbody/tr["+rowNum+"]/td/div/div/input")); 
      String poEligibleChecked = randomRow.getAttribute("checked");
      String element = js.executeScript("return arguments[0].getText();", poEligibleChecked).toString();
      System.out.println(element);
  </code></pre>
  
  <p>With similar null pointer exception error. </p>