title: Appium + Android + WebDriver findElement() : cannot find element after sendKeys()?
body: <p>I have a simulated Android device and Appium. My test successfully launches the right Activity and types in a particular text field. But when I try to find the same text field in order to check the text in it, I get <code>"An element could not be located on the page using the given search parameters."</code> Even if I try to re-use the element instead of searching for it a second time, it still fails with the same message. What should I do differently? Maybe the context for the second <code>findElement()</code> is wrong -- I can't find the button next to the text field either.</p>
  
  <p>Here's a git repo that contains an app and a test project. The failed JUnit test demonstrates the issue: <a href="https://github.com/achengs/an-appium-question" rel="nofollow">https://github.com/achengs/an-appium-question</a></p>
  
  <p>Details below (code and Appium log interleaved)</p>
  
  <p>Here's the first findElement which succeeds. The layout xml file for the Activity has this attribute for the text field that I'm looking for: <code>android:id="@+id/edit_message"</code></p>
  
  <pre><code>public static final String MESSAGE_TO_SEND = "edit_message";
  ...
  WebElement e = driver.findElement(By.id(MESSAGE_TO_SEND));
  </code></pre>
  
  <p>First findElement succeeds:</p>
  
  <pre><code>debug: Appium request initiated at /wd/hub/session/0ec259be-87e0-47f6-9279-da577fe29a07/element
  debug: Request received with params: {"using":"id","value":"edit_message"}
  info: Pushing command to appium work queue: ["find",{"strategy":"id","selector":"edit_message","context":"","multiple":false}]
  info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"edit_message","context":"","multiple":false}}
  info: [BOOTSTRAP] [info] Got command of type ACTION
  info: [BOOTSTRAP] [debug] Got command action: find
  info: [BOOTSTRAP] [debug] Finding edit_message using ID with the contextId: 
  info: [BOOTSTRAP] [info] Returning result: {"value":{"ELEMENT":"1"},"status":0}
  info: Responding to client with success: {"status":0,"value":{"ELEMENT":"1"},"sessionId":"0ec259be-87e0-47f6-9279-da577fe29a07"}
  POST /wd/hub/session/0ec259be-87e0-47f6-9279-da577fe29a07/element 200 5656ms - 109b
  </code></pre>
  
  <p>Saying hello!</p>
  
  <pre><code>String text = "hello!";
  e.sendKeys(text);
  </code></pre>
  
  <p>That succeeds:</p>
  
  <pre><code>debug: Appium request initiated at /wd/hub/session/0ec259be-87e0-47f6-9279-da577fe29a07/element/1/value
  debug: Request received with params: {"id":"1","value":["hello!"]}
  info: Pushing command to appium work queue: ["element:setText",{"elementId":"1","text":"hello!"}]
  info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"1","text":"hello!"}}
  info: [BOOTSTRAP] [info] Got command of type ACTION
  info: [BOOTSTRAP] [debug] Got command action: setText
  info: [BOOTSTRAP] [info] Returning result: {"value":true,"status":0}
  info: Responding to client with success: {"status":0,"value":true,"sessionId":"0ec259be-87e0-47f6-9279-da577fe29a07"}
  POST /wd/hub/session/0ec259be-87e0-47f6-9279-da577fe29a07/element/1/value 200 4215ms - 89b
  </code></pre>
  
  <p>Here's the second findElement which fails. (If I skip this findElement and re-use the original one -- or if I try to find the Send button next to the text field instead, I still get a similar failure)</p>
  
  <pre><code>WebElement f = driver.findElement(By.id(MESSAGE_TO_SEND));
  </code></pre>
  
  <p>Here's the log for the failure:</p>
  
  <pre><code>debug: Appium request initiated at /wd/hub/session/0ec259be-87e0-47f6-9279-da577fe29a07/element
  debug: Request received with params: {"using":"id","value":"edit_message"}
  info: Pushing command to appium work queue: ["find",{"strategy":"id","selector":"edit_message","context":"","multiple":false}]
  info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"edit_message","context":"","multiple":false}}
  info: [BOOTSTRAP] [info] Got command of type ACTION
  info: [BOOTSTRAP] [debug] Got command action: find
  info: [BOOTSTRAP] [debug] Finding edit_message using ID with the contextId: 
  info: [BOOTSTRAP] [info] Returning result: {"value":"No element found","status":7}
  info: Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"No element found"},"sessionId":"0ec259be-87e0-47f6-9279-da577fe29a07"}
  POST /wd/hub/session/0ec259be-87e0-47f6-9279-da577fe29a07/element 500 874ms - 223b
  </code></pre>
  
  <p>There was a request for the HTML. I'm testing a native Android app. Here's the layout xml for the current Activity under test. If there's something else I should include here, please do let me know.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal"&gt;
  &lt;EditText android:id="@+id/edit_message"
      android:layout_weight="1"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:hint="@string/edit_message" /&gt;
  &lt;Button
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="@string/button_send"
     android:onClick="sendMessage" android:id="@+id/send"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>