我们正在调查用JxBrowser替换JavaFx WebView的选项,以下代码片段可以正常使用WebView:
((HTMLInputElementImpl)document.getElementById("username")).setValueForUser("username");
((HTMLInputElementImpl)document.getElementById("password")).setValueForUser("password");
loginButton.click();
魔法由setValueForUser完成,使用标准setValue(“”)不起作用,因为表单提交/操作被禁用,除非有人实际点击了字段。
不幸的是我找不到使用JxBrowser实现相同逻辑的正确方法:
InputElement username = (InputElement) document.findElement(By.id("username"));
username.setValue("username");
username.click();
InputElement password = (InputElement) document.findElement(By.id("password"));
password.setValue("password");
password.click();
loginButton.click(); // or form.submit()
username.click()没有帮助。
我正在考虑模拟/发送鼠标事件到浏览器视图,但这将是一个混乱的解决方案。
那么在JxBrowser中有setValueForUser替代?
谢谢, -Alex