【问题标题】:Appium Submit UrlAppium提交网址
【发布时间】:2020-01-23 05:53:41
【问题描述】:

我正在使用 Python 和 Android Chrome。而我的WebDriver 是使用WebDriver.Remote(host, caps) 创建的

我实际上想在隐身模式下使用 Chrome,但根据question here 似乎不可能。

但是有什么解决方法吗?例如,我可以将我的 url 提交到 Chrome 顶部的 url 栏吗?我试过driver.find_element_by_id('com.android.chrome:id/url_bar').submit(),但它说没有实现。

【问题讨论】:

    标签: webdriver appium appium-android remotewebdriver python-appium


    【解决方案1】:

    您正在尝试使用 Appium 混合两种不兼容的移动自动化方法。

    1. 如果您想正常使用Selenium API,以便像控制桌面浏览器一样控制移动浏览器:

      • 像这样实例化您的 AppiumDriver:

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

        然后打开 URL 只需使用 driver.get() 函数,如:

        driver.get('http://example.com')
        
    2. 如果您想使用 Appium API 并将 Chrome 视为任何其他移动应用程序,您需要提供一组稍微不同的 desired capabilities 并指定 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)
      

    查看Appium - > Code Examples -> Python 文章,了解有关自动化移动浏览器/应用程序(包括代码 sn-ps)的更多信息

    【讨论】:

    • 感谢您的回答,但很抱歉您没有收到我的问题。我找到了解决方法并发布了。
    【解决方案2】:

    这是我的解决方法。解释在 cmets 中。

    # 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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多