我必须在 java 中的 selenium 测试的输入框中输入文本。我正在使用下面的代码来执行此操作,它输入字符但随后将其删除:
WebElement depart=webControls.getDriver().findElement(By.id("oneWayFlight_fromLocation"));((JavascriptExecutor) webControls.getDriver()).executeScript("document.getElementById('oneWayFlight_fromLocation').value='JFK'");
或者
((JavascriptExecutor) webControls.getDriver()).executeScript("arguments[0].value='JFK';",depart);
或者
((JavascriptExecutor) webControls.getDriver()).executeScript(String.format("document.getElementById('oneWayFlight_fromLocation').value='JFK';","JFK"));
这是文本字段:
<input id="oneWayFlight_fromLocation" type="text" class="InputText-control hasError hasIcon" name="oneWayFlight_fromLocation" placeholder="From" autocomplete="off" value="">
我遵循设置:
- 视窗 10 64 位
- IE11 32 位
- IE DriverServer 32 位
- 保护模式全部关闭
- nativeEvents 为假
- REQUIRE_WINDOW_FOCUS 为真
- 高级安全中未选中的 64 位进程