如何在硒中解雇JS事件? [英] How to fire JS event in selenium?

查看:97
本文介绍了如何在硒中解雇JS事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用selenium WebDriver语法。我知道,在基于selenium server的语法中,您可以通过执行以下操作来触发javascript事件:

I'm using selenium WebDriver syntax. I know, that in selenium server-based syntax, you can fire an javascript event by doing:

Selenium selenium = new DefaultSelenium("localhost", server.getPort(),
            "*iexplore", "http://www.eviltester.com");
selenium.fireEvent("lteq30", "blur");

如何在使用WebDriver创建的应用程序中执行相同操作(例如,FirefoxDriver)?

how do I do the same in an application, created with WebDriver (for example, FirefoxDriver)?

推荐答案

不幸的是,Selenium WebDriver设计师明确地决定不在Selenium 2中包含此功能。

Unfortunately the Selenium WebDriver designers explicitly decided not to include this functionality in Selenium 2.


这是故意决定不在WebDriver中包含此功能,
因为它通常是解决合成事件而不是
表现正常的黑客行为。我们宁愿通过为原生事件提供优惠的
支持来消除这种需求,因此我们将继续改进前进
。用户永远不会触发焦点事件,他们会单击
表单控件。这也是你的测试应该做的。

It's a deliberate decision to not include this feature in WebDriver, since it's usually a hack to work around synthesized events not behaving properly. We'd rather eliminate this need by providing great support for native events, so we'll continue improving that going forward. A user would never fire a focus event, they would click the form control. That's what your tests should be doing as well.

话虽如此,你可以执行任何javascript代码你要。因此,您应该查看如何使用javascript 触发事件。请查看此StackOverflow问题以获取灵感。

With that said, you can execute any javascript code you want. Thus you should look into how to fire events with javascript. Take at look at this StackOverflow question for inspiration.

然后你可以这样做:

FirefoxDriver driver = new FirefoxDriver();
driver.ExecuteScript("[your fire event javascript code]");

我确定你可以创建一个包装函数来基本上完成与<$ c $相同的事情c> fireEvent 。

I'm sure you could create a wrapper function to basically accomplish the same thing as fireEvent.

这篇关于如何在硒中解雇JS事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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