访问一个元素,在没有的Watir属性 [英] Accessing an element with no attributes in Watir

查看:189
本文介绍了访问一个元素,在没有的Watir属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用的Watir,有没有不带属性来访问元素的一种方法?

Using Watir, is there a way to access an element without attributes?

例如:

<span>Text</span>

我想避免使用XPath,但如果这是唯一的方式,它的凉爽。

I'd like to avoid using xpath, but if that's the only way it's cool.

推荐答案

无视其摆在首位的标签,或者从你的开发人员(或自己)请求独特属性的非的Watir的问题,你可以随时访问通过元素它的父元素,或索引。

Disregarding the non-WATIR issues of having tags in the first place, or requesting unique attributes from your developers (or yourself), you can always access an element via its parent elements, or by index.

例如:
    
       
          文本
       
    

For example: Text

@browser.div(:name => "content").span(:index => 1)
#this is the first span element inside this div

您可以通过你到达子跨度元素之前需要然而,许多独特的元素工作,不使用XPath。当然,你只需要一个独特的父元素以达到特定的子元素,并从下来的工作到孩子。

You can work through however many unique elements you need to before reaching the child span element, without using Xpath. Of course, you only need one unique parent element to reach that specific child element, and you work down from that to the child.

div(:how => what).table(:how => what).td(:how => what).span(:how => what).text

又如,假设它是在页面上的第n个的跨距:
       @ browser.span(:指数=>的 N 的)

该由指数的方法很脆,容易当任何更新页面破发,但是。

The by-index approach is very brittle and prone to breaking when any update is made to the page, however.

这篇关于访问一个元素,在没有的Watir属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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