I am trying to automate a web page using I开发者_运维知识库E and Watir. When I load the page with chrome and use development tools I can identify the field I need to fill, complete with its id and name.
Watir, however, is unable to find that field. I suspect it is due to the fact that it is buried deep inside an HTML hierarchy.
can I tell Watir to do a recursive search (in all frames, areas and sections) for that field?
if that is not possible, can I extract the element path from chrome development tool and use that in my script ?
If Watir can not find HTML element, any you know it is there, then it is probably in a frame.
More information: http://wiki.openqa.org/display/WTR/Frames
It is difficult to give you specific advice (exact code) without seeing the HTML, or at least the path to the object in question.
With the exception of frames (each of which acts like it's own unique web page) you only need to provide as much of the 'path' to an object as is needed to ensure uniqueness. For example if you had a Link where you did not know the URL in advance, and it has no unique text or identifier, BUT it was inside another 'container element like a div that had some unique name, class, id etc (or a combination of those) then you could identify the object from the container down. e.g.
browser.div(:how, what).link(:index, 0).click #note index would be 1 in watir 1.x, 0 in 2.x and watir-webdriver
In the case of frames, and especially (may the gods have pity upon you) Nested Frames, you need to specify ALL of the frames that are part of the path to the object, and then enough details to ensure it can be uniquely identified within the frame that contains the element you are trying to access.
(editorial): For the most part, from what I've seen, most modern websites eschew the use of frames except in a very few specific instances such as 'framing' a link to an external site (e.g. Linked-In's handling of links to other sites posted within it's group discussion threads) Use of a lot of frames is pretty much considered 'web 1.0' if not even 'pre 9/11' by a lot of folks who use CSS and other methods to achieve the same visual effects as using frames for sub-areas etc, without all the downsides of frames.
Sam, Watir searches the entire page by default regardless of where the element is located. My guess is that your how/what from the Watir browser command is incorrect. Can you please post your attempt at the text_field locator as well as the HTML code for the text field?
If you know the "how" using Chrome/Firefox/IE development tools (id, class, name, title, etc), and you know the "what" ("firstName", "MyTextField", "blue_text_field"), etc), then you can locate it using those specifics in Watir:
@browser.text_field(:how, what)
@browser.text_field(:id, "firstName")
Please check the documentation for these methods here: http://watir.com/documentation/
精彩评论