Let us see the procedure for automation of mobile web. Here we are automating the mobile web using a chrome browser on an Android device.
Make sure that the Mobile Browser version and Browser Driver should be in the same version.
If we are automating the mobile web using chrome browser then chrome browser version and chrome driver version should be the same.If not it will show error while executing error.
1st-way :
Launch the url in the desktop browser and inspect the values using chrome Dev tools as shown in the link.
2nd-way :
1. Inspecting the values from the mobile browser itself.Follow the below steps for 2nd way.
2. Connect the device to PC. Now open chrome browser and type "chrome://inspect/#devices"
3. Make sure the required url is launched before providing the above command in chrome.
4. Now this will show a list of devices connected along with a list of urls which are opened in the browser.
5. Click on the inspect for required url as shown in the image.
6. This will open a new window and here we can inspect the elements.
HybridAppAutomation.py
from appium import webdriver import time from selenium.common.exceptions import ElementNotVisibleException, ElementNotSelectableException, NoSuchElementException from selenium.webdriver.support.wait import WebDriverWait from appium.webdriver.common.appiumby import AppiumBy desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['automationName'] = 'UiAutomator2' desired_caps['platformVersion'] = '10' desired_caps['deviceName'] = 'Pixel' desired_caps['app'] = ('/Skill2Lead/Appium_Demo_App/Android/Android_Appium_Demo.apk') desired_caps['appPackage'] = 'com.android.chrome' desired_caps['appActivity'] = 'org.chromium.chrome.browser.ChromeTabbedActivity' # 1. Create the Driver object driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps) # 2. Create WebDriverWait wait = WebDriverWait(driver,25,poll_frequency=1,ignored_exceptions=[ElementNotVisibleException,ElementNotSelectableException,NoSuchElementException]) # 3. Open the URL in Browser ele = wait.until(lambda x: x.find_element(AppiumBy.ID,"com.android.chrome:id/terms_accept")) ele.click() ele2 = wait.until(lambda x: x.find_element(AppiumBy.ID,"com.android.chrome:id/negative_button")) ele2.click() ele3 = wait.until(lambda x: x.find_element(AppiumBy.ID,"com.android.chrome:id/search_box_text")) ele3.click() ele4 = wait.until(lambda x: x.find_element(AppiumBy.ID,"com.android.chrome:id/url_bar")) ele4.click() ele4.send_keys("https://www.google.com/") driver.press_keycode(66) time.sleep(5) # 4. Get the list of Contexts in App appContexts = driver.contexts print("AppContexts : ", appContexts) # 5. switch to webview to perform action on Required URL or on WebView for appType in appContexts: if appType == "WEBVIEW_chrome": driver.switch_to.context(appType) # 6. Do testing on Webview screen in chrome browser or any if we want ele4 = wait.until(lambda x: x.find_element(AppiumBy.XPATH,"//*[@name='q']")) ele4.send_keys("Skill2Lead") # 7. Switch back to native view to perform action for appType in appContexts: if appType == "NATIVE_APP": driver.switch_to.context(appType) # 8. Do testing on native app screen if we want ele4 = wait.until(lambda x: x.find_element(AppiumBy.ID,"com.android.chrome:id/url_bar")) ele4.click() ele4.send_keys("https://www.skill2lead.com/") driver.press_keycode(66) # 9. Quit or close the driver object time.sleep(5) driver.quit()