首页 > 解决方案 > 使用 appium 单击“离子切换”

问题描述

我无法<ion-toggle>使用 appium/python 客户端激活按钮。

这是 HTML 模板:

<ion-toggle id="testaut_useauth_toggle" 
            ng-change="toggleAuth()" 
            ng-model="wizard.useauth" 
            toggle-class="toggle-calm">{{'kWizUseAuth' |
          translate}}
</ion-toggle>

我的 appium test.py 代码:

self.click_item("testaut_useauth_toggle")
def click_item(self,id, wait=5):
        element = self.driver.find_element_by_id(id)
        element.click()
        sleep(wait)

我得到的错误:

selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: unknown error: Element <div class="item item-toggle toggle-small ng-not-empty ng-valid" id="testaut_useauth_toggle" ng-change="toggleAuth()" ng-model="wizard.useauth" toggle-class="toggle-calm" style="">...</div> is not clickable at point (180, 190). Other element would receive the click: <section ng-show="selected" ng-class="{current: selected, done: completed}" class="step current" ng-transclude="" wz-title="2" style="">...</section>
  (Session info: chrome=55.0.2883.91)

“其他元素”、“wz-title”基本上是我正在使用的角度向导模板。我的应用程序也在其他屏幕上使用它,我点击按钮没有问题,所以问题出在这个切换开关上(离子实现为复选框)

我尝试过但失败的替代方法:

def tap_item(self,id,wait=5):
        print ('Tapping item: {}'.format(id))
        element = self.driver.find_element_by_id(id)
        #self.driver.execute_script("arguments[0]).click();", element);
        self.driver.execute_script("document.getElementById(arguments[0]).click();", id);

这里没有错误,但是没有激活

任何帮助,将不胜感激。

鉴于这是一个网络应用程序,我真的无法获得任何位置。Tap 不起作用,因为该方法未针对 WebView 实现

标签: ionic-frameworkappiumappium-android

解决方案


<ion-toggle>在研究了按钮是如何实现的并且对哪个项目应该是点击的目标进行了一些实验后找到了一个解决方案

最终解决方案:

def tap_toggle(id,wait=Wait.TOGGLE):
    element = driver.find_element_by_id(id)
    element = element.find_element_by_tag_name('label')
    element.click()
    sleep(wait)

还交叉发布在https://github.com/appium/python-client/issues/340


推荐阅读