Watir-Webdriver框架属性不符合其他来源 [英] Watir-Webdriver Frame Attributes Not Congurent with Other Sources

查看:179
本文介绍了Watir-Webdriver框架属性不符合其他来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,如果我返回一个框架的一些属性,他们不匹配在萤火虫例如。原因是我正在寻找一种方法来确定一个框架的目的。例如在www.cnet.com上,它们总共加载了19个帧,其中一些是带有JavaScript的HTML。我想检查一些框架,但不是全部。

使用Firebug我看到了一些关于框架的有趣的属性,我想根据这些属性过滤框架。



我有以下Ruby代码来举例说明我需要的属性:

pre $ $ $ c> putsTag name:+ frame.attribute_value(tagName)
putsLocal name:+ frame.attribute_value(localName)
putsNode name:+ frame.attribute_value (nodeName)

输出如下:

 标签名称:IFRAME 
本地名称:iframe
节点名称:IFRAME

然而,这是Firebug for the childNodes / Children的页面www.cnet.com的输出:

< img src =https://i.stack.imgur.com/SWklA.jpgalt =在这里输入图片描述>



如果我参考Firebug

 标签名称:D IV 
本地名称:div
节点名称:DIV



任何帮助表示赞赏。

解决方案

答案是你没有要求Firefox显示给你的属性。



以顶部的DIV为例如果你想Watir返回gigya_ruler,那么你不得不要求div的ID属性,而不是名称。



同样的twitter中心框架。



将所有这些转换为Watir代码将如下所示:

  @b = Watir :: Browser.new:ff 

div = @ b.div(index:0)
puts div.id#=> 'gigya_ruler'

frame = @ b.iframe(index:0)
puts frame.id#=> 'twttrHubFrameSecure'


I have an issue where if I return the some attributes of a frame they do not match those in Firebug for example. The reason is that I am looking for a way to identify the purpose of a frame. For example on www.cnet.com they load 19 frames in total and some of these are HTML with JavaScript. I want to inspect some of the frames but not all.

Using Firebug I see some interesting attributes regarding the frame and I want filter the frame based on some of these attributes.

I have the following Ruby code to example the attributes I require:

puts "Tag name: " + frame.attribute_value("tagName")
puts "Local name: " + frame.attribute_value("localName")
puts "Node name: " + frame.attribute_value("nodeName")

The output is as follows:

Tag name: IFRAME
Local name: iframe
Node name: IFRAME

This, however is the output from Firebug for childNodes/Children for the page www.cnet.com:

If I refer to Firebug the first item on the list has the following attributes:

Tag name: DIV
Local name: div
Node name: DIV

BTW, I am using water-webdriver with headless under Firefox on Linux.

Any help is appreciated.

解决方案

The answer is you're not asking for the same attribute that Firefox is showing you.

Taking the case of the DIV that is at the top of your list, if you wanted Watir to return "gigya_ruler" then you'd have to ask for the div's ID attribute, not the name.

Same goes for the twitter hub frame.

Converting all this to Watir code would look like the following:

@b = Watir::Browser.new :ff

div = @b.div(index: 0)
puts div.id # => 'gigya_ruler'

frame = @b.iframe(index: 0)
puts frame.id # => 'twttrHubFrameSecure'

这篇关于Watir-Webdriver框架属性不符合其他来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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