appium / appium/java-client

Method MobileElement.getAttribute() throws NoSuchElementException

Open
#1,186 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.3k
Forks
752
Avg merge
6d 21h
Merged PRs (30d)
8

Description

Description

Call to element.getAttribute("MISSING_ATTR") throws NoSuchElementException in Appium, but returns null in Chrome, Firefox and others webdrivers. I believe Appium should also return null instead of throwing exception. It's a totally valid case when I want to log some attributes of the element. I don't want to write multiple try/catch blocks to do it.

Environment

  • io.appium:java-client:7.1.0
  • Appium server version: 1.7.2

Code To Reproduce Issue

assertNull(appiumDriver.findElement(By.id("result")).getAttribute("FOOBAR"));

Causes the exception:
https://gist.github.com/asolntsev/36ad1bdfce253cb5ba8210d1c2f909e0

Link to Appium logs

[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:getAttribute","params":{"attribute":"class","elementId":"5"}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"This element does not have the 'class' attribute"}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the Java client's MobileElement.getAttribute() path and compare its handling with the WebDriver behavior described in the issue. Reproduce the call using the provided assertNull example and add or update a regression test so a missing attribute returns null rather than NoSuchElementException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.