下面列出了怎么用org.openqa.selenium.ElementNotInteractableException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* @throws Exception on test failure
*/
@Test(expected = ElementNotInteractableException.class)
public void clickHiddenSubmit() throws Exception {
final String html = "<!DOCTYPE html>\n"
+ "<html><head></head>\n"
+ "<body>\n"
+ " <form id='myForm' action='" + URL_SECOND + "'>\n"
+ " <input id='myButton' type='submit' style='display: none;'>Submit</input>\n"
+ " </form>\n"
+ "</body></html>";
final String secondContent = "second content";
getMockWebConnection().setResponse(URL_SECOND, secondContent);
final WebDriver driver = loadPage2(html);
driver.findElement(By.id("myButton")).click();
}
@Test
public void synchronizeExplicit() {
driver.get("http://watir.com/examples/wait.html");
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("add_foobar")));
driver.findElement(By.id("add_foobar")).click();
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("foobar")));
try {
element.click();
session.stop(true);
} catch (ElementNotInteractableException e) {
session.stop(false);
Assert.assertTrue(e.getMessage(), false);
}
}
/**
* Simulate mouse click action
*/
@Override
@PublicAtsApi
public void click() {
new RealHtmlElementState(this).waitToBecomeExisting();
try {
WebElement element = RealHtmlElementLocator.findElement(this);
try {
element.click();
} catch (ElementNotInteractableException enie) {
if (!UiEngineConfigurator.getInstance().isWorkWithInvisibleElements()) {
throw enie;
}
((JavascriptExecutor) webDriver).executeScript("arguments[0].click()", element);
}
} catch (Exception e) {
throw new SeleniumOperationException(this, "click", e);
}
}
/**
* @throws Exception on test failure
*/
@Test(expected = ElementNotInteractableException.class)
public void clickInvisible() throws Exception {
final String html = "<html>\n"
+ "<body>\n"
+ " <a id='link' style='display: none'>Click me</a>\n"
+ "</body></html>";
final WebDriver driver = loadPage2(html);
driver.findElement(By.id("link")).click();
}
@Test
public void synchronizeSalsaVerde() {
browser.goTo("http://watir.com/examples/wait.html");
browser.element(By.id("add_foobar")).click();
try {
browser.element(By.id("foobar")).click();
session.stop(true);
} catch (ElementNotInteractableException e) {
session.stop(false);
Assert.assertTrue(e.getMessage(), false);
}
}
@Test
public void synchronizeAbstract() {
driver.get("http://watir.com/examples/wait.html");
click(By.id("add_foobar"));
try {
click(By.id("foobar"));
session.stop(true);
} catch (ElementNotInteractableException e) {
session.stop(false);
Assert.assertTrue(e.getMessage(), false);
}
}
public void clickEyeButton() {
if (isEyeButtonDisabled()) {
throw new ElementNotInteractableException("The eye button is disabled and cannot be clicked");
}
eyeButton.click();
}