【发布时间】:2023-02-23 23:17:18
【问题描述】:
我正在尝试使用 Selenium 更改字段的文本值。不幸的是,该字段不是 <input>,而是一个伪类为 ::before 的 div
我需要能够在此字段中输入新的文本值,但到目前为止还无法这样做。
HTML sn-p:
<div class="stb-LazyChosenDropdown" tabindex="0">
<div class="icon default" aria-hidden="true" style="display: none;"></div>
<div class="tiles">
<div class="input" contenteditable="true" placeholder="Enter values..." style="width: 383px; height: 17px;"></div>
::before
</div>
我可以使用以下内容打印已有的值:
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("return window.getComputedStyle(document.querySelector('div.stb-LazyChosenDropdown div.tiles div.input'),':before').getPropertyValue('content')")
System.out.println(content);
打印Enter values...
但是如何将文本值更改为新值呢?
【问题讨论】:
标签: javascript selenium-webdriver