getAttribute("class") returns a NoSuchElementException

Hi, I am testing an Android app with Appium 1.3.4.1. I’d like to output few attributes. But it is weird that I can get “checked” but not for “class”.

    WebElement element = _wd.findElementById("XXXXXX");
    System.out.println("checked="+element.getAttribute("checked"));  // print out "checked=true"
    System.out.println("class="+element.getAttribute("class"));          // NoSuchElementException

Here is the output, I got NoSuchElement exception.

checked=true

org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 15 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘2.43.1’, revision: ‘5163bceef1bc36d43f3dc0b83c88998168a363a0’, time: ‘2014-09-10 09:43:55’
System info: host: ‘SEANS-W540-W8’, ip: ‘10.220.2.220’, os.name: ‘Windows 8.1’, os.arch: ‘amd64’, os.version: ‘6.3’, java.version: ‘1.7.0_60’
Session ID: 3da5e447-fe32-45c7-908c-484c33ebf11b
Driver info: io.appium.java_client.android.AndroidDrive

Is there anybody can explain it?

Any help is appreciated.

Sean

any solutions to this?

More than likely the error is accurate and it simply couldn’t locate the element using the data you’ve provided.

  • Your locator is incorrect
  • You’re testing Android and the element is out of the viewable area

Someone can help you craft a correct locator if you paste the page source XML for your AUT.

getAttribute (“className”) will work.
Even I faced the same issue.

Regards,
Akshaj.