-
I am trying to find a button on this page: https://www.w3schools.com/csS/tryit.asp?filename=trycss_buttons_font , specifically the button which fits the following descriptions: xpath : /html/body/button[1] I have tried all the following to no avail:
So at this point I'm stumped. Is there any way to do this? Basically, I want to find and then click a button. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@jenko This button element inside a specific frame: irb(main):001:0> require 'ferrum'
=> true
irb(main):002:0> browser = Ferrum::Browser.new
=>
#<Ferrum::Browser:0x0000557ae873bc58
...
irb(main):003:0> browser.go_to("https://www.w3schools.com/csS/tryit.asp?filename=trycss_buttons_font")
=> "B518E51285C593532700AE92549906D9"
irb(main):004:0> browser.frames
[#<Ferrum::Frame @id="B518E51285C593532700AE92549906D9" @parent_id=nil @name=nil @state=:stopped_loading @execution_id=2>,
#<Ferrum::Frame @id="9D922C5348BFC0509623B8D35966C21E" @parent_id="B518E51285C593532700AE92549906D9" @name="iframeResult" @state=:stopped_loading @execution_id=3>,
#<Ferrum::Frame @id="C5161E1F986B4AE786FFFC06DDAF4D7F" @parent_id="B518E51285C593532700AE92549906D9" @name="__tcfapiLocator" @state=:stopped_loading @execution_id=4>,
#<Ferrum::Frame @id="3510AB3DA766A354F4BDE2AE4C945897" @parent_id="B518E51285C593532700AE92549906D9" @name="__uspapiLocator" @state=:stopped_loading @execution_id=5>]
irb(main):005:0> frame = browser.frame_by(name: "iframeResult")
=> #<Ferrum::Frame @id="9D922C5348BFC0509623B8D35966C21E" @parent_id="B518E51285C593532700AE92549906D9" @name="iframeResult" @state=:stopped_loading @execution_id=3>
irb(main):006:0> frame.at_css('html body button.button.button1')
=> #<Ferrum::Node @target_id="B518E51285C593532700AE92549906D9" @node_id=41 @description={"nodeId"=>0, "backendNodeId"=>24, "nodeType"=>1, "nodeName"=>"BUTTON", "localName"=>"button", "nodeValue"=>"", "childNodeCount"=>1, "attributes"=>["class", "button button1"]}>
irb(main):007:0> the_button = frame.at_css('button.button:nth-child(3)')
=> #<Ferrum::Node @target_id="B518E51285C593532700AE92549906D9" @node_id=41 @description={"nodeId"=>0, "backendNodeId"=>24, "nodeType"=>1, "nodeName"=>"BUTTON", "localName"=>"button", "...
irb(main):008:0> the_button = frame.at_xpath('/html/body/button[1]')
=> #<Ferrum::Node @target_id="B518E51285C593532700AE92549906D9" @node_id=41 @description={"nodeId"=>0, "backendNodeId"=>24, "nodeType"=>1, "nodeName"=>"BUTTON", "localName"=>"button", "... |
Beta Was this translation helpful? Give feedback.
@jenko This button element inside a specific frame:
need to use frames to got proper reference: