`
lilingjay
  • 浏览: 8388 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

Using watir-webdriver, how can I click a table row?

 
阅读更多

原文链接: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
分享到:
评论

相关推荐

    linux环境下watir-webdriver离线安装包

    在Linux环境下进行自动化测试时,Watir-Webdriver是一个非常有用的工具。它是一个Ruby库,允许用户使用Ruby语言控制浏览器,进行网页元素的交互和测试。Watir是“Web Application Testing in Ruby”的缩写,而...

    WATIR-WEBDRIVER自动化学习指导

    ### WATIR-WEBDRIVER自动化学习指导 #### 一、简介 WATIR-WEBDRIVER是一款基于Ruby语言的Web自动化测试框架,它能够帮助开发者和测试工程师编写高效的自动化测试脚本。WATIR(Web Application Testing In Ruby)与...

    ruby2.0.0+selenium-webdriver+watir-webdriver+rails离线备份

    ruby2.0.0+selenium-webdriver+watir-webdriver+rails离线备份,设置环境变量后可使用(未测试)

    watir-webdriver谷歌浏览器驱动

    ChromeDriver 是一款以 Google Chrome 为环境测试网站的工具,现已实现对开源的 WebDriver 通路协议的支持,因此可以轻松与现有的 WebDriver 测试工具相整合。不熟悉 WebDriver 的用户可以参考 2009 年的项目发布...

    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脚本

    使用watir-webdriver删除百度空间所有文章的ruby脚本

    test_logger1.rar_Logger wat_ruby _watir_watir ruby_watir-webdriv

    最后,“watir-webdriver”是Watir的一个分支,它利用Selenium WebDriver接口,直接与浏览器的内核进行通信,增强了对浏览器的控制能力,如处理JavaScript交互、模拟用户行为等。WebDriver是一个跨平台的标准,使得...

    watir-webdriver

    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-cn...

    watir安装所需要的gem包

    对于"watir安装所需要的gem包",主要涉及的Gem包有`watir-webdriver`和`selenium-webdriver`。`watir-webdriver`是Watir的一个版本,它使用Selenium WebDriver作为后端,与浏览器进行通信。而`selenium-webdriver`则...

    页面对象:在watir-webdriver和selenium-webdriver中实现PageObject模式的宝石

    它可以与watir和selenium-webdriver一起使用。 文献资料 项目是学习如何使用页面对象的第一个地方。 可以在上找到该项目的 。 要查看各个发行版之间的更改,请查看 要了解这种宝石的动机,请阅读此 有一本书...

    watir-bonus-1.5.2

    "Watir-Bonus-1.5.2" 是一个专门用于Web自动化测试的工具,它扩展了Watir(Web Application Testing in Ruby)的功能,提供了一系列额外的便利特性,旨在简化和增强网页应用的自动化测试过程。这个版本是1.5.2,表明...

    win7上搭建cucumber+watir自动化环境

    Watir-webdriver需要浏览器的WebDriver驱动,例如对于Internet Explorer,需要下载IEDriverServer,并将其放在Ruby安装目录下的bin文件夹中。同样,对于Chrome,需要下载ChromeDriver并放置在相同位置。 6. **环境...

    自动化测试框架

    1. **选择合适的工具和技术栈**:根据项目需求选择合适的编程语言(如Ruby)和测试框架(如Watir-WebDriver)。 2. **环境准备**:搭建必要的开发环境,例如安装Ruby、DevKit等。 3. **设计框架结构**:定义测试脚本...

    watir-bonus-1.5.1.1230.zip

    **标题:“Watir-Bonus-1.5.1.1230.zip”** 这个压缩包包含的是Watir的扩展版本1.5.1的1230次更新,名为“Bonus”。Watir(Web Application Testing in Ruby)是一个开源的Ruby库,用于自动化浏览器操作,它使得...

    watir-1.5.2.gem

    **Ruby和Watir自动化测试工具详解** Ruby是一种面向对象的编程语言,它的设计哲学强调简洁性和易读性,使得开发者可以高效地编写代码。作为解释型语言,Ruby不需要编译即可运行,同时还拥有强大的文本处理能力,...

    domkey:Selenium Watir Webdriver 的域特定页面组件

    Selenium Watir-Webdriver 的域特定页面组件页面组件首先对特定语义域进行建模,然后对浏览器代码进行建模。 Watir-Webdriver 是蜜蜂的膝盖! 现在使用域特定页面组件工厂!用法Domkey 是一个库,可帮助您构建用于...

    watir-1.6.5.gem

    开源自动化测试工具组合:Ruby+Watir安装 安装准备: 1. 工具安装包准备: Ruby官方下载地址:http://www.ruby-lang.org/zh_cn/downloads/,稳定版本Ruby 1.8.6 Watir下载地址:http://rubyforge.org/frs/?...

Global site tag (gtag.js) - Google Analytics