Java 类org.openqa.selenium.InvalidElementStateException 实例源码
项目:web-test-framework
文件:Element.java
/**
*
* @param <P>
* @param clazz
* @param env
* @return
*/
public <P extends Page> P fixUrlAndGotoLink(final Class<P> clazz, final Environment env) {
this.logAction("LOAD PAGE " + clazz);
return new RetryUntilTimeout<P>() {
@Override
P commandsToRun() {
String href = getAttribute("href");
try {
Assert.assertNotNull(env);
String newhref = env.fixHost(href);
driver.navigate().to(newhref);
return PageFactory.createPage(getDriver(), clazz);
} catch (MalformedURLException ex) {
getDriver().getStepLogger().log(WARN, "INVALID HREF ON LINK:" + href);
throw new InvalidElementStateException("INVALID HREF ON LINK:" + href);
}
}
}.run();
}
项目:ats-framework
文件:HtmlFileBrowse.java
/**
*
* @param webDriver {@link WebDriver} instance
* @param value the file input value to set
*/
protected void setFileInputValue( WebDriver webDriver, String value ) {
String locator = this.getElementProperties()
.getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR);
String css = this.getElementProperty("_css");
WebElement element = null;
if (!StringUtils.isNullOrEmpty(css)) {
element = webDriver.findElement(By.cssSelector(css));
} else {
element = webDriver.findElement(By.xpath(locator));
}
try {
element.sendKeys(value);
} catch (ElementNotVisibleException enve) {
if (!UiEngineConfigurator.getInstance().isWorkWithInvisibleElements()) {
throw enve;
}
// try to make the element visible overriding some CSS properties
// but keep in mind that it can be still invisible using another CSS and/or JavaScript techniques
String styleAttrValue = element.getAttribute("style");
JavascriptExecutor jsExec = (JavascriptExecutor) webDriver;
try {
jsExec.executeScript("arguments[0].setAttribute('style', arguments[1]);",
element,
"display:'block'; visibility:'visible'; top:'auto'; left:'auto'; z-index:999;"
+ "height:'auto'; width:'auto';");
element.sendKeys(value);
} finally {
jsExec.executeScript("arguments[0].setAttribute('style', arguments[1]);", element,
styleAttrValue);
}
} catch (InvalidElementStateException e) {
throw new SeleniumOperationException(e.getMessage(), e);
}
}
项目:TimesheetAutomation
文件:TimeSheet.java
public boolean fillTimeForTheDay(WebElement elemDay, int day){
try{
elemDay.sendKeys("8");
return true;
} catch (InvalidElementStateException e){
System.out.println(days[day] +" is not available yet. Too bad we can't fill time in advance...");
return false;
}
}
项目:ScriptDriver
文件:RunTests.java
public WaitFor(String cmd, StreamTokenizer tokenizer, boolean requiresContext) throws Exception {
if (requiresContext && null == selection) {
throw new Exception(cmd + " command requires a field selection at line " + tokenizer.lineno());
}
int retry = 0;
long now = 0;
do {
try {
this.run();
return;
} catch(StaleElementReferenceException e) {
// element has gone stale, re-select it
System.out.println("// EXCEPTION : StaleElementReference : " + e.getMessage().split("\n")[0]);
retry++;
} catch(InvalidElementStateException is) {
System.out.println("// EXCEPTION : InvalidElementStateException : " + is.getMessage().split("\n")[0]);
scrollContextIntoView(selection);
retry++;
} catch(WebDriverException e2) {
System.out.println("// EXCEPTION : WebDriverException : " + e2.getMessage().split("\n")[0]);
// Try and auto-recover by scrolling this element into view
scrollContextIntoView(selection);
retry++;
} catch(RetryException r) {
System.out.println("// EXCEPTION : RetryException : " + r.getMessage().split("\n")[0]);
// Try and auto-recover by scrolling this element into view
retry++;
} catch(Exception e3) {
System.out.println("// EXCEPTION : " + e3.getMessage().split("\n")[0]);
if (retry++ > 3) this.fail(e3);
}
// attempt to recover
now = (new Date()).getTime();
System.out.println(now + ": DEBUG: retry=" + retry + " calling sleepAndReselect(100) _waitFor = " + _waitFor);
if (retry == 1 && now >= _waitFor) {
System.out.println("// Wait timer already expired, apply default wait timer");
System.out.println("// wait " + (_defaultWaitFor*1.0)/1000.0);
_waitFor = (long) now + _defaultWaitFor;
}
sleepAndReselect(100);
} while (_waitFor > 0 && now < _waitFor);
// action failed
info(selection, selectionCommand, false);
_waitFor = 0; // wait timer expired
this.fail(new Exception(cmd + " failed at line " + tokenizer.lineno()));
}