Watir-Webdriver Frame Attributes Not Congurent wit

2019-09-18 23:15发布

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:

enter image description here

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.

1条回答
smile是对你的礼貌
2楼-- · 2019-09-19 00:10

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'
查看更多
登录 后发表回答