【问题标题】:Why MoveToElement no response为什么 MoveToElement 没有响应
【发布时间】:2021-09-02 03:24:11
【问题描述】:

我尝试通过 moveToElement 将鼠标移动到元素,但它不起作用。

代码如下

Actions action = new Actions(driver);
action.MoveToElement(element);
action.Perform();

我认为元素找到了,因为element.Click() 是工作

附:测试程序是windows下的win32程序。

【问题讨论】:

    标签: appium winappdriver appium-desktop


    【解决方案1】:

    执行操作也不适合我。我找到了自定义方法的方法。这是我在 Python 中的示例。

    def scroll_to_element(self, locator: str, timeout=2):
        by = get_locator_by_string(locator)
    
        def elem_none():
            try:
                WebDriverWait(self._driver, timeout).until(
                    ex_cond.invisibility_of_element_located(by), ' : '.join(by))
                return True
    
            except TimeoutException:
                return False
    
        for _ in range(10):
            if elem_none() is True:
    
                size = self._driver.get_window_size()
                startx, starty = int(size['width']) * 0.5, int(size['height']) * 0.8
                endx, endy = int(size['width']) * 0.5, int(size['height']) * 0.2
                self._driver.swipe(startx, starty, endx, endy, 1000)
    
                if elem_none() is False:
                    break
                else:
                    continue
    

    我的方法是刷 10 次。您可以将其更改为while,但这是一个不好的方法 - 如果找不到元素,测试将不会结束。 这种方式一直对我有用,对我来说就足够了。希望对您有所帮助!

    【讨论】:

    • 谢谢你的回答,我试试看。
    猜你喜欢
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 2020-03-16
    • 1970-01-01
    相关资源
    最近更新 更多