A
A
Andrey Blagovidov2017-01-12 17:41:58
Java
Andrey Blagovidov, 2017-01-12 17:41:58

How to insert text into the input of a page loaded in a webView?

Good afternoon. Decided to load a web resource in a webView. Now I'm trying to find a specific input and insert text into it, but so far without success. Has anyone experienced this and how did you resolve the issue?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rPman, 2017-01-12
@rPman

not with android but on java, javafx.scene.web.WebEngine (as I understand it is also used on android)
take the webEngine.getDocument() document to it, you can make requests like getElementById or getElementsByTagName, in general, almost all the same methods that are available in javascript (querySelector is not directly available), as a result you will get access to elements like org.w3c.dom.html.HTMLImageElement / HTMLInputElement and so on. which will have methods for setting value values ​​or simply accessing attributes by name.
Click emulation is also available directly from java, but I strongly recommend that everything that should call methods inside the browser in javascript be done by calling webEngine.executeScript, and if it is difficult to reach the element by its identifier (for example, it has neither a name nor an identifier), but you were able to get it object in java, you can pass it back to javascript like this:
final static string GET_NODE_TEXT = "unique_node_name";
...
// after page load
htmlWnd = (DOMWindowImpl)((DocumentView)htmlDoc).getDefaultView();
...
// an example of calling submit a form whose element we have in node
htmlWnd.setMember(GET_NODE_TEXT, node);
browser.executeScript("(function(){var x=window."+GET_NODE_TEXT+";x.form.submit();})()");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question