Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

ruby - Watir-Webdriver Frame Attributes Not Congurent with Other Sources

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...