Using Mechanize, is it possible to find a phrase in the HTML of a page, for example, \"email\", and find the next after that, and fill in that input
For a well-formed HTML page, an input
element should have a label
showing what the input
is for. In this case, you can iterate all label
, finding the one containing text "email"
, and get the associated input
by the for
attribute of the label
.
However, not all HTML page are well-formed. No label
, no for
attribute, or other ill-formed issues.
If you mean the input
right after some element in the DOM. You can do some DOM traversal to find whether an element containing "email"
has an input
element next to it.
If you mean the input
next to an element in the rendered page, you should define what is "next to". And I think you cannot get what you want without great efforts. Some element located after the element "email" might be placed before it with some CSS trick. You need some graphical API to find that input
. However, I don't see that in watir
's API documentation.