且构网

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

Java& Appium:无法点击元素

更新时间:2021-12-17 14:41:52

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

Here's the solution that worked for me:

  1. 使用 MobileElement .我也在使用AndroidDriver而不是RemoteWebDriver,所以我不知道这是否行得通.
  2. 忘记click().使用MobileElement的 tap(手指,整数持续时间)方法.我没有在互联网上找到持续时间是多少(秒,毫秒等,因此这些值仅是按&试用).
  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);
            }