Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4013726
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:24:26+00:00 2026-05-20T09:24:26+00:00

I recently attempted to use selenium RC’s GetAttribute method but immediately ran into a

  • 0

I recently attempted to use selenium RC’s GetAttribute method but immediately ran into a challenge. I tried to execute a very simple selenium.GetAttribute("//a/@href") but the code threw a SeleniumException with the message “ERROR: Could not find element attribute: //a/@href”.
By substituting selenium.GetText("//a[@href]") in place of the GetAttribute call, I confirmed that an element was definitely present, as this statement properly returned the text of the link.

I then tried:

  • pointing to a different web page with a different protocol (file:/// vs http://) — same problem.
  • using a different xpath locator pointing to a different attribute — same problem.
  • using a DOM locator selenium.GetAttribute("document.getElementsByTagName('a')[0].getAttribute('href')") — same problem; slightly different error message (and the error message is missing the final parenthesis): “ERROR: Element document.getElementsByTagName(‘a’)[0].getAttribute(‘href’ not found”. Note that this exact expression works correctly in Firebug’s console.
  • using absolute instead of relative xpath addressing, with selenium.GetText("xpath=/html/body/a[@href]") to confirm the existence and then selenium.GetAttribute("xpath=/html/body/a/@href") to get the attribute — and it worked!

While the manual clearly states that relative xpath locators do not need an explicit locator type (i.e. the “xpath=” prefix) it is silent about absolute 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 selenium.GetAttribute("//a/@href") to selenium.GetAttribute("xpath=//a/@href") — and this also worked!

Finally, my experiments with the very handy Find 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…

My questions:

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:

  1. Why does GetAttribute with an XPath locator type uniquely require an explicit locator type when other methods (e.g. GetText) do not?
  2. Why did the DOM locator fail with a ‘not found’ error? (The manual also clearly states that DOM locators do not require an explicit locator type prefix, but I nevertheless tried adding “dom=” as a prefix on the DOM test; it still failed.)
  3. Why does Selenium IDE not fail more gracefully when attempting to highlight (Find) an attribute? With the same "xpath=//a/@href" 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]”

Your input is also requested for the following: The pattern I wanted for each test here was (A) GetText(locator-for-element-with-attribute) to confirm the presence of the element then (B) GetAttribute(locator-for-attribute-itself). 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. Are there solutions for the remaining two slots?

Type    GetText       GetAttribute
XPath   //a[@href]    xpath=//a/@href
CSS     css=a[href]   ??
DOM     ??            document.getElementsByTagName('a')[0].getAttribute('href')

(Details: Selenium RC version 1.0.3, Browser: Firefox 3.6.13, My target code in C#)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:24:27+00:00Added an answer on May 20, 2026 at 9:24 am

    Selenium RC’s GetAttribute method returns the value of the element\attribute locator. The general form for these locators is

    "[locator (id, xpath, css, etc)]@[attribute name]"
    

    for example

    "SaveButton@href"
    

    returns the value of the href attribute on the element with the id SaveButton. Xpath locators can also be used:

    "xpath=//a[contains(@id, 'SaveButton')]@href"
    

    returns the value of the href attribute on the element whose id contains the text SaveButton.

    To answer your questions,

    • 1: I don’t really know, this is a question for the designers of Selenium.

    • 2: The Selenium commands execute several different “contexts”. In some of the commands, document refers to the web page under test, in other commands, document refers to the page containing the Selenium frame (testRunner.html I believe).

    • 3: The error message says that it cannot find the element you requested. The information after that could be useful to the Selenium team if there is actually a bug present, but doesn’t really affect you. The more information the better, right?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I ran into this error in my web application: java.lang.OutOfMemoryError: PermGen space It's
We recently attempted to add ip address validation to our website's login security. So
I recently found out that PHP not only has the fsock* functions, but also
I recently attempted adding Zen Coding to my tool box of software development box
I recently installed Umbraco 4.5.2 into an IIS application, not as the default web
I've just recently upgraded to SQL Server 2008 from 2005 and when I attempt
Recently Jeff has posted regarding his trouble with database deadlocks related to reading. Multiversion
Recently I have been investigating the possibilities of caching in ASP.NET. I rolled my
Recently, I started changing some of our applications to support MS SQL Server as
Recently, I've been dealing with an error with accessing MAPI via the .NET framework

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.