appium java 点击事件,Java& Appium:无法点击元素

In the Android app that I am testing, I am trying to click/tap the time picker. For example by default the time picker shows 08:00AM. I want to change the hour from 8 to 7 & then later on change the minutes but the xpath doesn't seem to be working. Its clicking something but the time still shows 08:00AM when I click the OK button via the code. If someone could help me then I will be able to change minutes & PM to AM as well.

Here's what I am using for tapping the hour picker so that 7 shows up selected:

driver.findElement(By.xpath("//android.widget.NumberPicker[0]/android.widget.Button[0]")).click();

Image:

FdJKy.png

解决方案

Here's the solution that worked for me:

Use MobileElement. I am using AndroidDriver also instead of RemoteWebDriver so I do not know whether that will work or not.

Forget click(). Use tap(int fingers, int duration) method of MobileElement. I have not found on the internet what duration is (seconds, milliseconds, etc so these values are just hit & trial).

I have posted the code below & it worked. It may need refinement but for now I am happy as I am not a hardcore programmer.

Now assume that hour is variable depending upon your test

// change hour

@SuppressWarnings("unchecked")

List buttons = driver.findElementsByClassName("android.widget.Button");

MobileElement hour = (MobileElement) buttons.get(0);

List highlights = driver.findElementsByClassName("android.widget.EditText");

MobileElement hourHighlight = (MobileElement) highlights.get(0); // highlighted hour

// lets say we need hour = 4

while (!hourHighlight.getText().equalsIgnoreCase("4"))

{

Thread.sleep(100);

if (hourHighlight.getText().equalsIgnoreCase("4"))

{

break;

}

hour.tap(1, 10);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值