Reputation: 3149
I'm a new comer to both Ruby (Watir) and Javascript. If an website uses Javascript code that dynamically (by clicking button or such) generates buttons, I have no idea how to access to them. It may have its own name or id, but I even can't check it, since the generated buttons aren't founded on the source code of a web page via browser...
I thought it could be an answer;
browser = Watir::Browser.new(:firefox)
browser.send_keys :tab
until I realized I seem not to have a way to refer to the focused button, even if I set the focus on the target by tab key...
EDIT: Thanks guys. I think it was a noob question now I just face another big problem (all the generated buttons share the exactly same attributes!!, so I can't specify which), but that's another story...
**EDIT2: I just solved my second question.
browser.button(:attribute => "same", :index => *).click
this!
Noob Question
2012.5 - 2012.5
Upvotes: 3
Views: 1362
Reputation: 46846
Firefox has a tool for inspecting elements. You should be able to right-click an element and select the 'Inspect Element' menu option. Then push the HTML button to view the source for that button.
Once you see the source, you should be able to determine its attributes to click the button like any other button (assuming the button is already made visible).
So you would have a script like:
browser = Watir::Browser.new(:firefox)
browser.goto('http://my.page')
#Click the button that generates the other buttons
browser.button(:id, 'generate_buttons_button').click
#Click the newly displayed buttons once they appear
generated_button = browser.button(:id, 'generated_button')
generated_button.wait_until_present
generated_button.click
Upvotes: 3