【问题标题】:Appium: Unable to perform click on a "+" buttonAppium:无法执行单击“+”按钮
【发布时间】:2020-02-12 10:53:54
【问题描述】:

我正在尝试自动化移动应用程序,但在尝试单击“+”添加新数据行时遇到问题。

从getsource(),元素的代码是

                <android.widget.ImageButton index="0" package="mobi.littlebytes.android.bloodglucosetracker" class="android.widget.ImageButton" text="" resource-id="mobi.littlebytes.android.bloodglucosetracker:id/fab" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[844,1558][1038,1752]" displayed="true" />
              </android.widget.RelativeLayout>

我失败的代码是

a.moveToElement(driver_App.findElement(By.xpath("//[@id='fab']"))).click().build().perform();

我也试过了

a.moveToElement(driver_App.findElement(By.xpath("//*[@id='mobi.littlebytes.android.bloodglucosetracker:id/fab']"))).click().build().perform();

但也失败了,即无法点击“+”按钮。希望得到建议。

我附上了按钮的图片

【问题讨论】:

    标签: appium


    【解决方案1】:

    尝试使用 xpath 点击元素:

    driver_App.findElement(By.xpath("//*[@resource-id='mobi.littlebytes.android.bloodglucosetracker:id/fab']")).click();
    

    【讨论】:

    • 谢谢@Sameer!你能教我你的代码与使用“包含”方法的解决方案有什么区别吗?
    • @Tester_at_work 我没有使用moveToElement 方法,因为该元素已经存在于页面上,contains 将给出包含该文本的所有元素,因此建议输入确切的文字
    猜你喜欢
    • 2020-03-26
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多