Finding next input element using Mechanize?

后端 未结 3 975
粉色の甜心
粉色の甜心 2021-01-20 22:00

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

3条回答
  •  礼貌的吻别
    2021-01-20 22:10

    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.

提交回复
热议问题