硒ActionChains缺少执行 [英] Missing perform for selenium ActionChains

查看:107
本文介绍了硒ActionChains缺少执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当定义但未实际应用动作链"时,这是非常常见的,有时很难发现问题.示例:

It is a very common and, sometimes, difficult to spot problem when "action chains" are defined but not being actually applied. Example:

# incorrect
ActionChains(driver).move_to_element(some_element).click(some_element)

相对于:

# correct
ActionChains(driver).move_to_element(some_element).click(some_element).perform()
                                                                       ^^^^^^^^^

如果没有perform(),ActionChains本质上将不执行任何操作,也不执行任何操作.

ActionChains would essentially do nothing and perform no action without perform().

有没有一种方法可以通过静态代码分析及早发现这种类型的问题?

Is there a way to catch this type of a problem early with static code analysis?

我还查看了PyCharm是否会对此发出警告,但是它没有报告发现可疑代码,这是可以理解的,因为如果没有perform()调用,它仍然是完全有效的Python.

I've also looked if PyCharm would warn about this, but it reports no suspicious code found which is understandable as without the perform() call it is still a perfectly valid Python.

还有 missing-perform ESLint规则.

There is also this missing-perform ESLint rule.

推荐答案

perform()

perform()方法执行所有存储的操作.

perform()

perform() method performs all stored actions.

根据

As per the implementation of ActionChains, perform() is just like another method from the ActionChains Class like move_to_element(), click() etc.

现在, ActionChains 类用于自动执行低级交互,例如鼠标移动,鼠标按钮操作,按键和上下文菜单交互,这对于执行复杂的操作(如悬停,拖动和拖动)很有用.通过方法链接删除.

Now, ActionChains Class is used to automate low level interactions such as mouse movements, mouse button actions, key press, and context menu interactions which are useful for doing complex actions like hover over and drag and drop through method chaining.

文档中明确提到,要在调用ActionChains对象上的操作方法时生成用户操作,这些操作将存储在 ActionChains 对象中的队列中.最后,当您调用perform()时,事件将按照排队的顺序触发.

The documentation clearly mentions, to generate user actions when you call methods for actions on the ActionChains object, the actions are stored in a queue in the ActionChains object. Finally, when you call perform(), the events are fired in the order they are queued up.

按照这种逻辑,您很正确地指出 ...如果没有perform() ... ,ActionChains本质上不会执行任何操作,也不会执行任何操作,并且没有办法捕捉到这一点静态代码分析早期的问题类型.

So going by this logic, you were pretty correct to point out ...ActionChains would essentially do nothing and perform no action without perform()... and there is no way to catch this type of a problem early with static code analysis.

即使是IDE,例如 Eclipse PyCharm 甚至是专有 Python 应用程序编程接口(API)不会对此发出警告.

Even the IDEs, for example Eclipse, PyCharm or even Sublime Text3 a proprietary cross-platform source code editor with a Python application programming interface (API) wouldn't warn about this.

例如, Eclipse 不会抱怨缺少perfrom():

但是 Eclipse 会抱怨缩进:

这些情况类似于经典的情况,即

These cases are similar to the classic case of the IDEs not complaining when expected_conditions which should be called with a tuple and it is not a function, but actually a class, whose initializer expects just 1 argument beyond the implicit self:

class element_to_be_clickable(object):
    # .....
    def __init__(self, locator):
        # .....

IDE快照:

这篇关于硒ActionChains缺少执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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