Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAttribute for class name of a WebElement throws NoSuchElementException #355

Closed
namannigam-zz opened this issue Apr 7, 2016 · 4 comments
Labels

Comments

@namannigam-zz
Copy link

Description

Using getAttribute for class name of a WebElement throws NoSuchElementException even when the element exists on the screen.

Environment

  • java client build version or git revision if you use some shapshot: 3.4.0
  • Appium server version : Version 1.4.13 (Draco)
  • Mobile platform/version under test: Android
  • Real device or emulator/simulator: Emulator && Real Device
  • Driver : AppiumDriver

Details

http://stackoverflow.com/questions/36478130/using-getattribute-to-get-the-class-name-of-a-webelement

Went through the java docs of getAttribute. Couldn't understand the point mentioned as :

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

Couldn't understand if webElement.getAttribute("class") shall return the class name of the element or not?

Code To Reproduce Issue [ Good To Have ]

WebElement webElement = <findElement using some locator strategy>; System.out.println("element " + webElement.getAttribute("class"));

Exception stacktraces

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: 13 milliseconds

Link to Appium logs

Pushing command to appium work queue: ["element:getAttribute",{"elementId":"2","attribute":"class"}]
2016-04-07 14:19:08:721 - info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"This element does not have the 'class' attribute"},"sessionId":"9fd3b49c-5495-48c0-a2b3-a62c7bb44b98"}
2016-04-07 14:19:08:723 - info: <-- GET /wd/hub/session/9fd3b49c-5495-48c0-a2b3-a62c7bb44b98/element/2/attribute/class 500 9.562 ms - 227
2016-04-07 14:19:08:724 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getAttribute","params":{"elementId":"2","attribute":"class"}}
2016-04-07 14:19:08:724 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
2016-04-07 14:19:08:724 - info: [debug] [BOOTSTRAP] [debug] Got command action: getAttribute
2016-04-07 14:19:08:724 - info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":7,"value":"This element does not have the 'class' attribute"}

@TikhomirovSergey
Copy link
Contributor

Hmm... It is interesting. I'll open an issue here: https://github.com/appium/appium

@TikhomirovSergey
Copy link
Contributor

@namannigam
I've found the solution.
You should use 'className' instead of 'class'.
There lists of supported attrubutes:

I'm waiting for your response and then I'm closing this issue. You can close it on your own.

@namannigam-zz
Copy link
Author

@TikhomirovSergey 👍 it works, Please correct me if I am wrong, I believe just the doc for WebElement is a bit mis-leading in this case. Thanks. Lets close this with one final comment over the doc.

@TikhomirovSergey
Copy link
Contributor

I think that some Selenium attributes (html tags) are not convenient to native app automation. This thing should be documented.

#321

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants