title: Complications with Selenium's GetAttribute method
body: <p>I recently attempted to use selenium RC's <strong>GetAttribute</strong> method but immediately ran into a challenge. I tried to execute a very simple <code>selenium.GetAttribute("//a/@href")</code> but the code threw a SeleniumException with the message <em>"ERROR: Could not find element attribute: //a/@href"</em>.
  By substituting <code>selenium.GetText("//a[@href]")</code> in place of the <strong>GetAttribute</strong> call, I confirmed that an  element was definitely present, as this statement properly returned the text of the link.</p>
  
  <p>I then tried:</p>
  
  <ul>
  <li>pointing to a different web page with a different protocol (file:/// vs http://) -- same problem.</li>
  <li>using a different xpath locator pointing to a different attribute -- same problem.</li>
  <li>using a DOM locator <code>selenium.GetAttribute("document.getElementsByTagName('a')[0].getAttribute('href')")</code> -- same problem; slightly different error message (and the error message is missing the final parenthesis):  <em>"ERROR: Element document.getElementsByTagName('a')[0].getAttribute('href' not found"</em>. Note that this exact expression works correctly in Firebug's console.</li>
  <li>using absolute instead of relative xpath addressing, with <code>selenium.GetText("xpath=/html/body/a[@href]")</code> to confirm the existence and then <code>selenium.GetAttribute("xpath=/html/body/a/@href")</code> to get the attribute -- and it worked!</li>
  </ul>
  
  <p>While the manual clearly states that <strong>relative</strong> xpath locators do not need an explicit locator type (i.e. the "xpath=" prefix) it is silent about <strong>absolute</strong> xpath locators; I interpret from this that the prefix is required. But out of curiousity, I went back to my relative expression and added the explicit prefix--changing <code>selenium.GetAttribute("//a/@href")</code> to <code>selenium.GetAttribute("xpath=//a/@href")</code> -- and this also worked!</p>
  
  <p>Finally, my experiments with the very handy <strong>Find</strong> button in Selenium IDE show that it does fine with elements but fails with attributes. I can understand that it is not meaningful to highlight an attribute since attributes are not visible page elements, but why not highlight the element containing the attribute, and make it in a different color? Perhaps not a trivial task...</p>
  
  <h2>My questions:</h2>
  
  <p>I distilled the results of the above experiments down to these questions; this is the whole purpose of my posting here! Each of these seems like a bug to me but let me know if you think my usage is incorrect or there is a workaround:</p>
  
  <ol>
  <li>Why does GetAttribute with an XPath locator type uniquely require an <em>explicit</em> locator type when other methods (e.g. GetText) do not?</li>
  <li>Why did the DOM locator fail with a 'not found' error? (The manual also clearly states that DOM locators do <em>not</em> require an explicit locator type prefix, but I nevertheless tried adding "dom=" as a prefix on the DOM test; it still failed.)</li>
  <li>Why does Selenium IDE not fail more gracefully when attempting to highlight (Find) an attribute? With the same <code>"xpath=//a/@href"</code> locator, pressing the Find button yields this ugly message: "[error] locator not found: xpath=//a/@href, error = [Exception... "Could not convert JavaScript argument arg 0 [inIFlasher.scrollElementIntoView]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: chrome://selenium-ide/content/selenium-runner.js :: showElement :: line 386" data: no]"</li>
  </ol>
  
  <p>Your input is also requested for the following: The pattern I wanted for each test here was (A) <strong>GetText</strong>(<em>locator-for-element-with-attribute</em>) to confirm the presence of the element then (B) <strong>GetAttribute</strong>(<em>locator-for-attribute-itself</em>). Of the 6 slots in the table below I solved 3 of them successfully as just detailed, and a 4th seems to be a bug. <strong>Are there solutions for the remaining two slots?</strong></p>
  
  <pre>
  Type    GetText       GetAttribute
  XPath   //a[@href]    xpath=//a/@href
  CSS     css=a[href]   ??
  DOM     ??            document.getElementsByTagName('a')[0].getAttribute('href')
  </pre>
  
  <p>(Details: Selenium RC version 1.0.3, Browser: Firefox 3.6.13, My target code in C#)</p>