由于支持的“暂停”命令,硒动作“ move_to_element”在Safari中不起作用 [英] Selenium action 'move_to_element' doesn't work in Safari because of usupported 'pause' command

查看:201
本文介绍了由于支持的“暂停”命令,硒动作“ move_to_element”在Safari中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在自动化测试期间,下一个命令在Safari浏览器上失败:

The next command is failed on Safari browser during automation testing:

ActionChains(driver).move_to_element(searchInput).perform()

例外:


InvalidArgumentException:消息:在有效负载中遇到
无效值的键输入源:{actions =({duration = 0; type =
pause;});
id =键;
type = key;}

InvalidArgumentException: Message: Encountered key input source with invalid 'value' in payload: {actions = ({duration = 0;type = pause;}); id = key; type = key;}

整个精确测试示例:

def test_safari2(self):
    driver = webdriver.Safari()
    driver.get('https://www.wikipedia.org')
    locator = (By.ID, 'searchInput')

    # 1. the line below is passed
    searchInput = WebDriverWait(driver, timeout=30).until(expected_conditions.visibility_of_element_located(locator))

    # 2. the line below is failed in Safari, but passed in Chrome, FF
    ActionChains(driver).move_to_element(searchInput).perform()

但是!如果在动作 move_to_element()内对 self.w3c_actions.key_action.pause()进行注释,则整个动作链均有效!

However! If self.w3c_actions.key_action.pause() is commented inside action move_to_element(), then the whole Action chains works!

def move_to_element(self, to_element):
    """
    Moving the mouse to the middle of an element.

    :Args:
     - to_element: The WebElement to move to.
    """
    if self._driver.w3c:
        self.w3c_actions.pointer_action.move_to(to_element)
        # self.w3c_actions.key_action.pause()
    else:
        self._actions.append(lambda: self._driver.execute(
                             Command.MOVE_TO, {'element': to_element.id}))
    return self

与其他动作类似的情况。
我的问题是:
是Safari的已知限制吗?因此,ActionChais命令不能用于Selenium + Safari吗?还是有一些配置特殊性?

The similar situation with other actions. My question is: Is it is known limitation of Safari? And therefore ActionChais command could not be use for Selenium + Safari? Or there is some configuration pecularity?

我的测试运行程序配置:

My test runner configuration:


  • OS :Mac HighSierra 10.13.6

  • Safari 12.0(13606.2.11)

  • 硒:3.14.1

  • Python:2.7.14

  • 使用w3c功能和协议启动Safari(即driver.w3c = True)

  • OS: Mac HighSierra 10.13.6
  • Safari 12.0 (13606.2.11)
  • Selenium: 3.14.1
  • Python: 2.7.14
  • Safari is started with w3c capabilities and protocol (i.e. driver.w3c=True)

问题背景:
我有一个足够完善的框架,其中包含许多适用于Chrome和Firefox的操作和测试。现在,我也尝试扩大Safari浏览器的覆盖范围。因此,这就是为什么我要寻找不起作用的动作链的解决方案

Issue background: I have an enough developed framework with a lot of actions and tests that work Ok for Chrome and Firefox. Now I'm trying to extend coverage for Safari browser also. So, that is why I'm searching for solution for not working ActionChains

推荐答案

通过包装 ActionChains来解决类,这样就不会使用 key_action.pause (这似乎没有任何重要作用):

Workaround by wrapping ActionChains class so that key_action.pause is not used (which does not seem to serve any important purpose):

import selenium.webdriver

class ActionChains(selenium.webdriver.ActionChains):
    def __init__(self, driver):
        super(ActionChains, self).__init__(driver)
        if driver.name in ('Safari', 'Safari Technology Preview'):
            self.w3c_actions.key_action.pause = lambda *a, **k: None

这篇关于由于支持的“暂停”命令,硒动作“ move_to_element”在Safari中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆