原文链接:http://stackoverflow.com/questions/5721438/using-watir-webdriver-how-can-i-click-a-table-row
Question:
I'm trying to convert my old watir scripts to use watir-webdriver instead, as that will (eventually) support IE9 and Firefox 4. $browser.table_row(:id => "account_1").click
is what I used to click the first row of a table on screen in watir/firewatir, but the API for this was modified in watir-webdriver. Now, the code is this: $browser.table(:class => "sortable")[0].click
which should grab the first row of the table then click it. It seems to be successful, as it continues code execution, but it doesn't actually click the row.
Can someone explain what the right syntax would be in this case?
Here's the source code around the area I want to click:
<table class="sortable">
<thead>
<tr id="">
<th> </th>
<th class="sort" > Name </th>
<th class="sort" > Number </th>
</tr>
</thead>
<tbody>
<tr id="account_1" onclick=";$('timer').show();; new Ajax.Request('create_new_account', {asynchronous:false, evalScripts:true, onComplete:function(request){;$('timer').hide();initializeCustomEffects();}})">
<td></td>
<td class="sortTd">Test Account</td>
<td class="sortTd">1</td>
</tr>
</tbody>
Answer:
A1:
our code is finding the first row of the table, which is inside the<thead>
and does not have an onclick handler. Try this instead:
browser.tr(:id => "account_1").click
Here's a script that demonstrates the behavior, and here's an overview of the revised table API.
A2:A Row isn't an HTTP object that would normally respond to a click. Is there something inside the row like a link that you want to click on, or is the row itself setup using event handling to respond to a particular event such as 'onclick' or 'onmousedown' ??
If the former, try actually clicking on the object within the row. If the latter then try experimenting with the .fire_event method and different events.
For example:
browser.table(:class => "sortable")[0].fire_event("onmousedown")
or maybe
browser.table(:class => "sortable").row(:index, 0).fire_event("onmousedown")
(addendum) AH now that we have the HTML we can see where the onclick handler is and as pointed out by Jarib, you were clicking on the header row (which is technically the first row of the table) To click the thing you want, you need something along the lines of
browser.row(:id, "account_1").click
browser.row(:text, /Test Account/).click
browser.table(:class => "sortable").row(:index, 1).fire_event("onclick")
(unless your intent is to sort the table, in which case I suspect you need to click a CELL in the first (header) row in order to sort the table on that column.
browser.cell(:text, ' Name ').click
发表评论
-
Get values from a select list using xpath [closed]
2012-04-04 16:50 0http://stackoverflow.com/que ... -
How do I build Watir tests for websites?
2012-04-04 16:14 0http://stackoverflow.com/que ... -
“TypeError: can't convert String into Integer” when trying to CTRL+click or SHIF
2012-04-04 15:33 0http://stackoverflow.com/que ... -
Using Watir, how can I select a radio control using both name and value?
2012-04-04 15:23 0q http://stackoverflow.com/q ... -
Selecting multiple options in select list with shift
2012-04-04 15:19 0Q http://stackoverflow.com/ques ... -
Drag-and-Drop in Watir
2012-04-04 15:15 0http://www.cheezyworld.com/2010 ... -
How to test onclick in this object without id
2012-04-04 15:13 0http://stackoverflow.com/que ... -
Browser Certificates
2012-04-04 15:01 0http://watirwebdriver.com/b ... -
selected_options returns blank from iframe
2012-04-04 14:48 0link http://stackoverflow.com/q ... -
How to handle tinyMCE when automating with watir-webdriver?
2012-04-04 14:28 0I'm evaluating Watir-webdr ... -
Browser url not returning new url
2012-04-01 17:55 0Qhttp://stackoverflow.com/quest ... -
Can not drive Opera with watir-webdriver on Windows XP
2012-04-01 17:53 0Qhttp://stackoverflow.com/quest ... -
why must I sleep or wait using watir-webdriver and firefox?
2012-04-01 17:50 0Qhttp://stackoverflow.com/quest ... -
Firefox 4 with watir webdriver: Need help using helperApps.neverAsk to save CSV
2012-04-01 17:39 0Q http://stackoverflow.com/q ... -
Watir Webdriver counting number of items in a UL list
2012-04-01 17:22 0Q http://stackoverflow.co ... -
finding the direct child of a tag in watir
2012-04-01 17:13 0Qhttp://stackoverflow.com/quest ... -
How to determine browser type (IE, FF, Chrome, etc.)
2012-04-01 16:59 0Q http://stackoverflow.com/que ... -
Wait methods for watir-webdriver unsuccessful with JS/AJAX and new page load (Er
2012-04-01 16:19 0http://stackoverflow.com/questi ... -
How to send text to a CKEditor WYSIWYG editor box using Watir-WebDriver
2012-04-01 16:14 0Q http://stackoverflow.com/ques ... -
How can I get Browser.text.include? to be case insensitive?
2012-04-01 15:57 0Q:http://stackoverflow.com/ques ...
相关推荐
ruby2.0.0+selenium-webdriver+watir-webdriver+rails离线备份,设置环境变量后可使用(未测试)
Watir-WebDriver是基于ruby开发web驱动框架 double_click 双击事件 ie .sikuli_image(:image=>"1.png").double_click right_click 右击事件 exist? 判断用户元素是否存在 edit = ie.text_field(:name,"username") ...
ChromeDriver 是一款以 Google Chrome 为环境测试网站的工具,现已实现对开源的 WebDriver 通路协议的支持,因此可以轻松与现有的 WebDriver 测试工具相整合。不熟悉 WebDriver 的用户可以参考 2009 年的项目发布...
WATIR-WEBDRIVER自动化测试指导
linux下离线安装watir-webdriver
压缩包中包含目前2013/01/19最新的安装文件,有rubyinstaller-1.9.2-p136、DevKit-tdm-32-4.5.1-20101214-1400-sfx、rubygems-1.8.24、watir-4.0.2、watir-webdriver-0.6.2等文件,并附上简略安装说明。
使用watir-webdriver删除百度空间所有文章的ruby脚本
wairt-webdriver.aip包含了chromedriver.exe、DevKit。、IEDriverServer.exe rubyinstaller-2.1.5.exe、Ruby语言入门教程v1.0这几个文件,是使用wati-webdriver进行安装部署以及ruby语言学些所需要的必不可少的资料...
watir-cn中文语言包 watir-cn中文语言包 watir-cn中文语言包 watir-cn中文语言包 watir-cn中文语言包 watir-cn中文语言包 watir-cn中文语言包 watir-cn中文语言包 watir-cn中文语言包 watir-cn中文语言包 watir-cn...
它可以与watir和selenium-webdriver一起使用。 文献资料 项目是学习如何使用页面对象的第一个地方。 可以在上找到该项目的 。 要查看各个发行版之间的更改,请查看 要了解这种宝石的动机,请阅读此 有一本书...
ruby 自动化测试,watir是一个很不错的东西
watir-webdriver IE支持 IEDriverServer
Watir 提供了丰富的开发库,封装了包括浏览器窗口 windows,button, link, dialog, image, table, div 等绝大多数 HTML 对象类型,方便测试人员快速构建自动化测试程序。
Selenium Watir-Webdriver 的域特定页面组件页面组件首先对特定语义域进行建模,然后对浏览器代码进行建模。 Watir-Webdriver 是蜜蜂的膝盖! 现在使用域特定页面组件工厂!用法Domkey 是一个库,可帮助您构建用于...
开源自动化测试工具组合:Ruby+Watir安装 安装准备: 1. 工具安装包准备: Ruby官方下载地址:http://www.ruby-lang.org/zh_cn/downloads/,稳定版本Ruby 1.8.6 Watir下载地址:http://rubyforge.org/frs/?...
watir开发文档。包括帮助文档,示例等等
ruby 2.00 selenium webdriver,watir webdriver 备份打包
web自动化测试用的工具。需要先安装ruby
2.3.8...C:\>gem install watirSuccessfully installed firewatir-1.6.5Successfully installed nokogiri-1.4.3.1-x86-mswin32Successfully installed watir-1.6.53 gems installed... ////////// suggested by ...