在Selenium和IEx中解决变更事件? [英] Firing change events in Selenium and IEx?

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

问题描述

我刚刚开始使用Selenium,所以我仍然把头包裹在所有活动部件周围。我已经启动并运行了我的第一个测试套件,但是在我的生活中无法在IE中触发jQuery事件监听器。

I'm just getting started on Selenium, so I'm still wrapping my head around all the moving parts. I've got my first test suite up and running, but can't for the life of me get jQuery event listeners to fire in IE.

这在以下问题上尤其成问题动态AJAX下拉菜单,例如 $('#country')。live('change',showStates)
select - > id =国家| label =美国

This is especially problematic on dynamic AJAX dropdowns such as $('#country').live('change',showStates) select -> id=country | label=United States

selenium驱动程序触发事件以响应所有其他浏览器的测试脚本,但我没有尝试过任何原因或强制更改事件。我已经尝试过使用我在SO上找到的所有方法,包括:

The selenium driver triggers the events in response to the test script for all other browsers, but nothing I've tried causes or forces the change event to fire. I've tried using every method I could find documented on SO, including:

  • Maintaining window focus per How to fire JS event in selenium?
  • Trying different methods to invoke the trigger: runScript -> "$('#country').change() per Selenium IE change event not fired
  • runScript -> "$('#country').trigger('change')
  • fireEvent -> id=country | change per onchange event does not get fired on selenium type command

这些命令都不会在IE9,8(模拟)或7中触发事件(仿真)。 FWIW目前还不清楚这些是否会导致事件在其他浏览器中触发,因为其他浏览器在没有额外调用的情况下触发更改事件。我在Windows 7上运行独立的selenium jar 2.33。

None of these commands fire the event in IE9, 8 (emulated) or 7 (emulated). FWIW It's unclear if these actually cause the event to fire in other browsers as the other browsers fire the change event without an additional call. I'm running the standalone selenium jar 2.33 on Windows 7.

如何使用selenium在IE中触发更改事件?

推荐答案

根据我的经验,直接触发javascript / jQuery并不是最安全的方法。而是尝试使用UI交互来模拟用户。例如,要触发'country.change()'事件,只需使用Selenium更改国家/地区字段中的国家/地区(您可能需要在该字段外删除)。我相信这是预期用途。

From my experience triggering javascript/jQuery directly is not the safest way to go about things. Instead try use UI interactions to simulate a user. For example to trigger the 'country.change()' event, just change the country in the country field using Selenium (you may have to tab out of the field). I believe this is the intended use.

我发现一些下拉列表可能很痛苦。我会在您的下拉列表中尝试以下一组操作:

I have found some Drop-down Lists can be painful. I would try the following set of actions on your Drop-down List:


  1. 获取当前选择的选项(在最顶层的元素上调用getText) DDL)

  2. 点击DDL(显示选项)

  3. 获取显示选项列表

  4. 发现当前选项与预期之间的距离

  5. 发送适当数量的DOWN或UP键(取决于方向),然后按ENTER或TAB键

  1. Get the currently selected option (call a getText on the topmost element of the DDL)
  2. Click the DDL (to display the options
  3. Get a list of displayed options
  4. Discover the distance between the current option and the intended
  5. Send the appropriate number of DOWN or UP keys (depending on direction) followed by a ENTER or TAB key

使用第三方UI包时,我不得不遵循这种过程,它将DDL与处理DDL操作的地方分开格式化。这意味着当Selenium与元素进行交互时,它不会发生预期的效果,因为它们是通过javascript在其他地方处理的,而不是在Selenium具有句柄的元素的上下文中。发送键模仿用户操作并强制javascript执行自己。让我知道我这是不清楚的,是否有效。

I have had to follow this sort of process when working with a third party UI package that formats the DDL separately from where it handles the manipulation of the DDL. This means when Selenium is interacting with the element it is use to the intended effects do not occur because they are being handled elsewhere by javascript that is not with in the context of the element Selenium has the handle of. Sending keys mimics a users actions and forces the javascript to execute itself. Let me know if this is unclear and whether it works.

这篇关于在Selenium和IEx中解决变更事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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