我到底是如何得到这个 Javascript 方法的
$('#principal_uid').change(function() {
if($(this).val().length > 0){
window.location.href = "/switch.html" + "?uid=" + $(this).val();
} else {
window.location.href = "/index.html";
要使用我的 Selenium WebDdriver 测试,我尝试在哪里更改字段的值?问题是该字段有一个默认值,但 Selenium clear() 方法没有清除它,尽管测试通过了。
我尝试了一些东西
WebElement field =driver.findElement(By.id("principal_uid"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("$('#principal_uid').change");
field.clear();
field.sendKeys("newValue"+Keys.RETURN); //CHRASHED THE TEST WITH ERROR COMMUNICATING REMOTE SERVER ERROR