1

I am using Python and Android Chrome. And my WebDriver is created using WebDriver.Remote(host, caps)

I actually want to use Chrome in incognito mode but it seems not possible according to the question here.

But are there any workaround? For example, can I submit my url to the url bar of Chrome at the top? I have tried driver.find_element_by_id('com.android.chrome:id/url_bar').submit() but it says not implemented.

Seaky Lone
  • 992
  • 1
  • 10
  • 29

2 Answers2

1

This is my workaround. Explanations are in the comments.

# Open Menu/More Button
d.find_element_by_id('com.android.chrome:id/menu_button').click()

# Click On Incognito Mode
d.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ListView/android.widget.LinearLayout[3]').click()

# Find Url Bar on the top
url_bar = d.find_element_by_id('com.android.chrome:id/url_bar')

# Click on it which gives you another view.
url_bar.click()

# Set url and this gives you a list of options
url_bar.set_text('https://a.lianwifi.com/app_h5/jisu/wifiapk/sms.html?c=uvtest&type=1')

# Click the first one. This is the one that leads you to the page with your url.
d.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.ListView/android.view.ViewGroup[1]/android.view.ViewGroup').click()
Seaky Lone
  • 992
  • 1
  • 10
  • 29
0

You're trying to mix 2 incompatible approaches to mobile automation using Appium.

  1. If you want to use Selenium API normally in order to control mobile browser like a desktop browser:

    • Instantiate your AppiumDriver like:

      desired_caps = {}
      desired_caps['platformName'] = 'Android'
      desired_caps['browserName'] = 'chrome'
      driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
      

      then to open the URL just use driver.get() function like:

      driver.get('http://example.com')
      
  2. If you want to use Appium API and treat Chrome as any other mobile application you need to provide a little bit different set of desired capabilities and specify Chrome package and activity

    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['appPackage'] = 'com.android.chrome'
    desired_caps['appActivity'] = 'com.google.android.apps.chrome.Main'
    driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
    

Check out Appium - > Code Examples -> Python article for more information on automating mobile browsers/applications including code snippets

Dmitri T
  • 159,985
  • 5
  • 83
  • 133