500 when failing to locate an element - Android

I was going to open an issue in Github for this but since I’m new to appium I figured I’d post here in case I’m missing something obvious. I’m getting a 500 back from the appium server when I’m trying to locate an element by xpath or id that doesn’t exist on the screen. Anyways, here’s everything I had in the issue I was about to post via a github issue.

The problem

The server is returning endless 500s on this route: POST /wd/hub/session/94a7e4d4-a190-4f4c-8d7f-3faae4ba82c2/element.


  • Appium version (or git revision) that exhibits the issue: 1.6.4 (REV 2f20a42292e7d8d8f9ae9286632155a46e599700)
  • Last Appium version that did not exhibit the issue (if applicable): N/A
  • Desktop OS/version used to run Appium: OS X El Capitan 10.11.6
  • Node.js version (unless using Appium.app|exe): 6.10.2
  • Mobile platform/version under test: Android / 7.1.1 & 6.0
  • Real device or emulator/simulator: emulator
  • Appium CLI or Appium.app|exe: CLI


It looks like this POST route, /wd/hub/session/94a7e4d4-a190-4f4c-8d7f-3faae4ba82c2/element passes in a blob like:
and then should return a 200 with ELEMENT in a blob like:

ELEMENT is then used in a subsequent call to check if element is displayed with
GET /wd/hub/session/7a4cc40a-7fd4-406b-ade5-062e00a737d3/element/6/displayed
and then calls to take action on element with
POST /wd/hub/session/4e003a40-b7b5-4ae9-9be8-99c3f4e18c4e/element/6/click

However, if I pass in an incorrect id or Xpath, the server bombs and returns 500s after returning a blob like {"status":7,"value":"No element found"} before I’m able to check if its displayed or click on it

Link to Appium logs

This gist shows the server initialization, a successful call to locate and element and an unsuccessful call to locate an element.

Code To Reproduce Issue [ Good To Have ]

I have this method in a BasePage. All my Page Objects extend getElement and pass in a string representing either an id or xpath. This is where the 500 happens in my test. I’m using a fluentDriver, however you can see in my gist that it’s not an issue with the wrong driver being used in this snippet.

public FluentElement getElement(String elementName) { // If the string starts with "//", the element is located via XPath // If not, it's located via ID if (elementName.startsWith("//")) { Assert.assertTrue(getfd().element(By.xpath(elementName)).isDisplayed()); return getfd().element(By.xpath(elementName)) .waitUntil(MAX_TIME) .ifElementIsNotDisplayed(); } else { Assert.assertTrue( //TODO: 500 is happening here getfd().element(By.id(elementName)).isDisplayed()); return getfd().element(By.id(elementName)) .waitUntil(MAX_TIME) .ifElementIsNotDisplayed(); } }

This is my first time submitting an issue here so please let me know if you need more information! I read the wiki and other issues to make sure this seemed :+1: