I am not able to find the elements from android.webkit.WebView in my native app.
I was able to retrieve the username and password field attributes by setting setWebContentsDebuggingEnabled to TRUE, and then by opening the webview in DevTools chrome://inspect/#devices
I have written the Python script to run the app :
# -*- coding: utf-8 -*-
#!/usr/bin/python
import os
import unittest
import time, re
try:
import c as s
except:
ImportError
sys.stderr.write("Error: Cannot find the 'c.py' file")
from time import sleep
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class AndroidTestsUpdatedMoreOptions(unittest.TestCase):
@classmethod
def setUpClass(self):
"Setup for the test"
desired_caps = {}
desired_caps['browserName']=''
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.2'
desired_caps['deviceName'] = 'karthikphone1'
desired_caps['app'] = s.APK_PATH
desired_caps['noReset'] = 'true'
desired_caps['fullReset'] = 'false'
desired_caps['appPackage'] = 'com.xxx.yyy'
desired_caps['app-activity'] = '.SplashActivity'
#desired_caps['newCommandTimeout'] = 5000
desired_caps['app-wait-activity'] = '.AuthorizationCodeActivity'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def test_User_enters_credentials(self):
element = WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.ID, "toolbar")))
print (" ")
self.assertEqual('NATIVE_APP', self.driver.current_context)
elementUsername = WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.XPATH, '//*[@id="oauth2_authorization_email"]')))
elementUsername.send_keys(s.SANDBOX_USERNAME)
elementUsername.send_keys(Keys.RETURN)
print('USERNAME- pass')
elementPassword = WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.XPATH, '//*[@id="oauth2_authorization_password"]')))
elementPassword.send_keys(s.SANDBOX_PASSWORD)
elementPassword.send_keys(Keys.RETURN)
print('PASSWORD- pass')
print(' ')
#The tearDown() method runs after every test.
@classmethod
def tearDownClass(self):
"Tear down the test"
self.driver.quit()
#---START OF SCRIPT
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(AndroidTestsUpdatedMoreOptions)
unittest.TextTestRunner(verbosity=2).run(suite)
Output :
karthik@dkarnik2-Vostro-3558:~/appiumworkspace$ python credentials.py
test_User_enters_credentials(__main__.AndroidTestsUpdatedMoreOptions)
ERROR
======================================================================
ERROR: test_User_enters_credentials(__main__.AndroidTestsUpdatedMoreOptions)
Traceback (most recent call last):
File "credentials.py", line 69, in test_User_enters_credentials
elementUsername = WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.XPATH, '//*[@id="oauth2_authorization_email"]')))
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/support/wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
TimeoutException: Message:
----------------------------------------------------------------------
Ran 1 test in 41.430s
FAILED (errors=1)
karthik@dkarnik2-Vostro-3558:~/appiumworkspace$
Where am I going wrong ?? Can someone help me please !!!
These questions might look similar, but none has been answered correctly..
Can't find an element on a webview page of an iOS native app using Appium
Can't find an element on a webview page of an android native app using Appium