English 中文(简体)
Retrieve <TD> text using WATIR
原标题:Retrieve <TD> text using WATIR

I am using WATIR for automated testing, and I need to copy in a variable the value of a rate. In the example below (from webpage source code), I need that variable myrate has value 2.595. I know how to retrieve value from <input> or <span> (see below), but not directly from a <td>. Any help? Thanks

<TABLE>
<TR>
    <TD></TD>
    <TD>Rate</TD>
    <TD>2.595</TD>
</TR>
</TABLE>

For a <span> I use this code:

raRetrieved = browser.span(:name =>  myForm.raNumber ).text
最佳回答

试图这样做,发现你想要使用定期表达来与载有字率的行文相对应的行文,然后将第三行的案文放在行。

myrate = browser.tr(:text, /Rate/).td(:index => 2).text
 #or you can use the more user-friendly aliases for those tags
myrate = browser.row(:text, /Rate/).cell(:index => 2).text

如果该表的其他案文中可能出现该比例,但一直只是你所希望的行文第二行的入门,则发现该行与该正文的相处,则使用父母的方法确定该行的行文,随后从第三行获得案文。

myrate = browser.cell(:text,  Rate ).parent.cell(:index => 2).text

.cell/code> &.row vs .td &.tr应由您决定,有些人喜欢标,其他人则喜欢描述性更强的名字。 无论你认为如何使用,守则对你或将与之合作的人来说是最可读的。

注:以上代码假定使用Watir-Webdriver,或Watir 2.x,两者均使用零基指数。 旧版本的Watir将指数值改为3

就记录而言,我完全同意其他人关于你所贴出的法典样品缺乏可检测性的意见。 它hor。 寻找适当的要素,如身份识别价值或名称,在使网页更容易测试方面并非行不通。

问题回答

为此:

browser.td(how, what).text

这里的问题是:table,trtd tags没有任何属性。 你们可以尝试这样的东西(没有测试):

browser.table[0][2].text

如果能帮助任何有相同问题的人,那么,它正为我工作:

browser.td(:text => "Rate").parent.cell(:index, 2).text

感谢大家





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签