且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java &Appium:无法点击元素

更新时间:2021-08-12 17:22:08

以下是对我有用的解决方案:

Here's the solution that worked for me:

  1. 使用MobileElement.我也在使用 AndroidDriver 而不是 RemoteWebDriver,所以我不知道这是否可行.
  2. 忘记点击().使用 MobileElement 的 tap(int finger, int duration) 方法.我还没有在互联网上找到什么是持续时间(秒、毫秒等,所以这些值只是点击和试用).
  1. Use MobileElement. I am using AndroidDriver also instead of RemoteWebDriver so I do not know whether that will work or not.
  2. 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<WebElement> buttons = driver.findElementsByClassName("android.widget.Button");
            MobileElement hour = (MobileElement) buttons.get(0);
            List<WebElement> 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);
            }