由于支持的“暂停”命令,硒动作“ move_to_element”在Safari中不起作用

时间:2018-10-23 11:11:28

标签: selenium selenium-webdriver safari action webdriverwait

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

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()

例外:

  

InvalidArgumentException:消息:遇到键输入源   有效负载中的无效“值”:{actions =({duration = 0; type =   暂停;});               id =键;               类型=键;}

整个改进的测试示例:

self.w3c_actions.key_action.pause()

但是!如果在动作move_to_element()中对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 进行了注释,则整个动作链都有效!

45
56
74
62

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

我的测试运行器配置:

  • 操作系统:Mac HighSierra 10.13.6
  • Safari 12.0(13606.2.11)
  • 硒:3.14.1
  • Python:2.7.14
  • Safari使用w3c功能和协议(即driver.w3c = True)启动

问题背景: 我有一个足够完善的框架,其中包含许多可以在Chrome和Firefox上正常运行的操作和测试。现在,我也尝试扩展Safari浏览器的覆盖范围。所以,这就是为什么我要寻找不起作用的ActionChains的解决方案

1 个答案:

答案 0 :(得分:0)

通过包装ActionChains类以便不使用key_action.pause(这似乎没有任何重要作用)的解决方法:

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