Selenium webelement.clear()上的元素似乎已过时错误
我正在用HtmlUnitDriver查找一个元素。元素是文本字段(输入) 我尝试使用username.clear()清除其内容。但这给了我 元素似乎已过时。您是否从包含它的页面导航到别处Selenium webelement.clear()上的元素似乎已过时错误,selenium,junit,Selenium,Junit,我正在用HtmlUnitDriver查找一个元素。元素是文本字段(输入) 我尝试使用username.clear()清除其内容。但这给了我 元素似乎已过时。您是否从包含它的页面导航到别处 没什么意义,因为我不会在页面间移动。有人知道这是什么吗?您可以尝试一下,看看它是否有效: public static WebElement getElementByLocator( By locator ) { driver.manage().timeouts().implicitlyWait( 5, Ti
没什么意义,因为我不会在页面间移动。有人知道这是什么吗?您可以尝试一下,看看它是否有效:
public static WebElement getElementByLocator( By locator ) {
driver.manage().timeouts().implicitlyWait( 5, TimeUnit.SECONDS );
WebElement we = null;
boolean unfound = true;
while ( unfound ) {
try {
we = driver.findElement( locator );
unfound = false; // FOUND IT
} catch ( StaleElementReferenceException e ) {
unfound = true;
Thread.sleep(4000);
}
}
}
driver.manage().timeouts().implicitlyWait( DEFAULT_IMPLICIT_WAIT,
TimeUnit.SECONDS );
return we;
}
那么
查找
username
后,您还执行了哪些其他操作。sendKeys要输入另一个用户名,请将处理该元素的整个代码部分张贴出来。
public static WebElement getElementByLocator( By locator ) {
driver.manage().timeouts().implicitlyWait( 5, TimeUnit.SECONDS );
WebElement we = null;
boolean unfound = true;
while ( unfound ) {
try {
we = driver.findElement( locator );
unfound = false; // FOUND IT
} catch ( StaleElementReferenceException e ) {
unfound = true;
Thread.sleep(4000);
}
}
}
driver.manage().timeouts().implicitlyWait( DEFAULT_IMPLICIT_WAIT,
TimeUnit.SECONDS );
return we;
}
WebElement username = getElementByLocator( By.id("username") );
username.clear();
username.sendKeys("myValue");