'Android webview not able to locate same element on second time
I am successfully able to switch context from Native app to WebView and vice-versa, but when I am executing the same steps for second time, at that time I am getting NoSuchElementException error. When I used getPageSource(), there I am getting previous visited page source i.e. second Page
Application Flow:
- Switched to WebView_
- Perform Activity on 1st page, when executed 2nd time I am getting 2nd Page page source
- Perform Activity on 2nd page,
- Switched back to NativeApp
Appium Environment Details:
- Appium version: 1.22.3 CLI
- Android Version: Android 12 Executed
- Environment : emulator
First Web Page
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> </title>
</head>
<body>
<form name="TransactionForm" id="TransactionForm" method="post" action="/transaction.do" autocomplete="off">
<div id="ordertotal" class="span12 border innerpanel-bg innerpanel-text pull-right">
<div class="span12 innerpanel-text order-details-title hidden-phone">
Payment Details
</div>
<div class="span12 innerpanel-text order-no">
<span class="pull-left">
Reference No.:
</span>
<span class="order-value">
RBL8ybXJQQGQi9
</span>
</div>
</div>
</form>
</body>
</html>
Second Web Page
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> </title>
</head>
<body>
<form method="post" action="./PaymentCancel.aspx" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="" />
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" />
<div></div>
</form>
</body>
</html>
This is error that I am getting
2022-04-16 02:37:23:706 [HTTP] --> GET /wd/hub/session/459b7826-8f0f-4321-8dc8-fadd746dad28/source
2022-04-16 02:37:23:707 [HTTP] {}
2022-04-16 02:37:23:707 [W3C (459b7826)] Driver proxy active, passing request on via HTTP proxy
2022-04-16 02:37:23:708 [WD Proxy] Matched '/wd/hub/session/459b7826-8f0f-4321-8dc8-fadd746dad28/source' to command name 'getPageSource'
2022-04-16 02:37:23:708 [WD Proxy] Proxying [GET /wd/hub/session/459b7826-8f0f-4321-8dc8-fadd746dad28/source] to [GET http://127.0.0.1:8000/wd/hub/session/053655c5ba9990a7bd056b131cebc396/source] with no body
2022-04-16 02:37:23:709 [Chromedriver] [STDERR] [1650076643.709][INFO]: [053655c5ba9990a7bd056b131cebc396] COMMAND GetSource {
2022-04-16 02:37:23:710 [Chromedriver] [STDERR] }
2022-04-16 02:37:23:710 [Chromedriver] [STDERR] [1650076643.709][INFO]: Waiting for pending navigations...
2022-04-16 02:37:23:711 [Chromedriver] [STDERR] [1650076643.709][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=263) C41003041B44623FC8598D1BCE563383 {
2022-04-16 02:37:23:711 [Chromedriver] [STDERR] "expression": "1"
2022-04-16 02:37:23:711 [Chromedriver] [STDERR] }
2022-04-16 02:37:23:715 [Chromedriver] [STDERR] [1650076643.715][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=263) C41003041B44623FC8598D1BCE563383 {
2022-04-16 02:37:23:718 [Chromedriver] [STDERR] "result": {
2022-04-16 02:37:23:718 [Chromedriver] [STDERR] "description": "1",
2022-04-16 02:37:23:718 [Chromedriver] [STDERR] "type": "number",
2022-04-16 02:37:23:719 [Chromedriver] [STDERR] "value": 1
2022-04-16 02:37:23:719 [Chromedriver] [STDERR] }
2022-04-16 02:37:23:720 [Chromedriver] [STDERR] }
2022-04-16 02:37:23:720 [Chromedriver] [STDERR] [1650076643.715][INFO]: Done waiting for pending navigations. Status: ok
2022-04-16 02:37:23:720 [Chromedriver] [STDERR] [1650076643.715][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=264) C41003041B44623FC8598D1BCE563383 {
2022-04-16 02:37:23:721 [Chromedriver] [STDERR] "awaitPromise": true,
2022-04-16 02:37:23:721 [Chromedriver] [STDERR] "expression": "(function() { // Copyright (c) 2012 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\n/**\n * Enum f...",
2022-04-16 02:37:23:722 [Chromedriver] [STDERR] "returnByValue": true
2022-04-16 02:37:23:723 [Chromedriver] [STDERR] }
2022-04-16 02:37:23:723 [Chromedriver] [STDERR] [1650076643.722][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=264) C41003041B44623FC8598D1BCE563383 {
2022-04-16 02:37:23:724 [Chromedriver] [STDERR] "result": {
2022-04-16 02:37:23:724 [Chromedriver] [STDERR] "type": "object",
2022-04-16 02:37:23:725 [Chromedriver] [STDERR] "value": {
2022-04-16 02:37:23:725 [Chromedriver] [STDERR] "status": 0,
2022-04-16 02:37:23:726 [Chromedriver] [STDERR] "value": "\u003Chtml xmlns=\"http://www.w3.org/1999/xhtml\">\u003Chead>\u003Ctitle>\n\n\u003C/title>\u003C/head>\n\u003Cbody>\n \u003Cform method=\"post\" action=\"./PaymentCancel.aspx\" id=\"form1\">\n\u003Cinput type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEW..."
2022-04-16 02:37:23:726 [Chromedriver] [STDERR] }
2022-04-16 02:37:23:727 [Chromedriver] [STDERR] }
2022-04-16 02:37:23:727 [Chromedriver] [STDERR] }
2022-04-16 02:37:23:728 [Chromedriver] [STDERR] [1650076643.722][INFO]: Waiting for pending navigations...
2022-04-16 02:37:23:731 [Chromedriver] [STDERR] [1650076643.722][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=265) C41003041B44623FC8598D1BCE563383 {
2022-04-16 02:37:23:732 [Chromedriver] [STDERR] "expression": "1"
2022-04-16 02:37:23:732 [Chromedriver] [STDERR] }
2022-04-16 02:37:23:733 [WD Proxy] Got response with status 200: {"value":"<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>\n\n</title></head>\n<body>\n <form method=\"post\" action=\"./PaymentCancel.aspx\" id=\"form1\">\n<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\"aleE/7H3BN6BEWf+XdDKzoB51Aa4E50X5VR51B8/Mk5J1MjjyGMR0JZP4fxN0ScavtuVLk06qEPGlDJKYNrWrvRy14FKCcPOIvmKcvsbzKQ=\">\n\n<input type=\"hidden\" name=\"__VIEWSTATEGENERATOR\" id=\"__VIEWSTATEGENERATOR\" value=\"DACA2748\">\n <div>\n \n </div>\n </form>\n\n\n</body></html>"}
2022-04-16 02:37:23:734 [HTTP] <-- GET /wd/hub/session/459b7826-8f0f-4321-8dc8-fadd746dad28/source 200 27 ms - 520
Also complete log attached here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
