Selenium 2 WebDriver实现无法正确处理可扩展菜单 [英] Selenium 2 WebDriver implementation not handling expandable menus correctly

查看:151
本文介绍了Selenium 2 WebDriver实现无法正确处理可扩展菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,点击一个按钮(比如EXPAND_CONTEXT_MENU,在内部实现为href)会导致隐藏的上下文菜单在其下展开,之后我点击上下文菜单中的菜单项。

I have a web page where clicking on a button (say EXPAND_CONTEXT_MENU, implemented internally as an href) causes a hidden context menu to expand under it, after which I click on of the menu items in the context menu.

由于Selenium 2不允许直接访问隐藏元素,我首先点击EXPAND_CONTEXT_MENU,然后点击所需的菜单项。

Since Selenium 2 does not allow direct access to hidden elements, I first click on EXPAND_CONTEXT_MENU and then click the desired menu item.

尝试测试此解决方案时,InternetExplorerDriver会显示一种特殊行为。首次单击EXPAND_CONTEXT_MENU可以扩展菜单,但在第二次单击(用于选择菜单项)之前,EXPAND_CONTEXT_MENU将再次最小化。当第二次单击发生时,这会导致ElementNotVisibleException。

While attempting to test this solution, InternetExplorerDriver displays a peculiar behavior. The first click on EXPAND_CONTEXT_MENU expands the menu alright, but before the second click (for selecting the menu item) can occur, EXPAND_CONTEXT_MENU gets minimized again. This results in an ElementNotVisibleException when the second click occurs.

FirefoxDriver执行此测试。我正在使用IE8和Firefox进行测试。

FirefoxDriver performs this test fine. I am using IE8 and Firefox for testing.

注意 - 在实际的AUT中,只需将鼠标悬停在EXPAND_CONTEXT_MENU上即可扩展上下文菜单。

Note - in the actual AUT, just a hover on EXPAND_CONTEXT_MENU expands the context menu.

推荐答案

可能存在未正确触发的事件绑定。尝试通过jquery触发不同的事件(假设驱动程序是WebDriver实例,并且元素是您要触发事件的元素):

There is probably an event binding that is not firing correctly. Try firing different events via jquery (assumes that driver is the WebDriver instance and that element is the element you want to fire the event on):

((IJavaScriptExecutor)driver).ExecuteScript(string.Format("$(arguments[0]).trigger('click');", element);

这篇关于Selenium 2 WebDriver实现无法正确处理可扩展菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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