我正在尝试将字段填充到一个eo.webbrowser控件中,该控件将这些字段显示在一个模态对话框中。
对话框:https://imgur.com/a/d9NZhjm
HTML:https://imgur.com/a/1crV3Zd
我试过了: eowvMain.EvalScript("document.getElementById('rule-0-property-0').value='TEST';");
但是我得到了这个错误: EO.WebBrowser.JSException:',第1行,col50-51: Uncaught :无法设置空属性(设置'value')‘
有人能指出正确的方向吗?
编辑:这似乎改变了文本框中的内容,而不是实际值。
eowvMain.EvalScript("document.querySelector('[data-test="rule-0-property-0"]').value='TEST';");发布于 2022-02-25 20:41:42
该输入没有rule-0-property-0的id,因此使用getElementById('rule-0-property-0')将获得null。
备选案文1
相反,使用querySelector应该有效:
eowvMain.EvalScript("document.querySelector('[data-test=\"rule-0-property-0\"]').value='TEST';");在设置值之后,有几种分配值的方法。如果要防止这种情况发生,则需要克隆对象以删除所有的事件侦听器。即使如此,这也不是一件容易的事,如果是窗口上的事件侦听器随后搜索元素,您仍然可以体验到一个事件处理程序覆盖它。而且,如果该元素依赖于这些事件侦听器中的任何一个,则可能会遇到其他问题。
string evalScript = @"
//Find the element through a data attribute selector
var element = document.querySelector('[data-test=\"rule-0-property-0\"');
var clone = element.cloneNode(true);
//replace the element to remove all of its event listeners
element.outerHTML = clone.outerHTML;
element.value = 'TEST';
element.setAttribute('value','TEST');
";
eowvMain.EvalScript(evalScript);选项2
向该输入元素添加一个id并使用getElementById:
<input id="rule-0-property-0" data-test="rule-0-property-0" class="input" placeholder="Trait *" />https://stackoverflow.com/questions/71238815
复制相似问题