0

these's my java code.

WebDriver driver = new FirefoxDriver();
for (DBTable table : tables) {
	try {
		Thread.sleep(10000l);
		String content = templeteService.generateTemplate(table);
		content = content.replaceAll("\\r|\\n|\\t", "");
		String title = table.getComment();
		//跳转到内容父页面
		driver.get(topUrl);
		String curUrl = driver.getCurrentUrl();
		//如果重定向到登录页,则登录
		if (curUrl.indexOf("/confluence/login.action") != -1) {
			driver.findElement(By.id("os_username")).sendKeys("kehui");
			driver.findElement(By.id("os_password")).sendKeys("kehui.1225");
			driver.findElement(By.id("loginButton")).click();
		}
		//点击创建按钮
		driver.findElement(By.id("create-page-button")).click();
		//点击生成默认的空白页
		driver.findElement(By.className("create-dialog-create-button")).click();
		Thread.sleep(1000l);
		//wiki标题
		driver.findElement(By.id("content-title")).sendKeys(title);
		//切换到wiki内容页,并填充标题
		driver.switchTo().frame("wysiwygTextarea_ifr");
		WebElement editor = driver.findElement(By.tagName("body"));
		JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
		jsExecutor.executeScript("document.body.innerHTML = '" + content + "';", editor);
		driver.switchTo().defaultContent();
		//driver.findElement(By.id("notifyWatchers")).click();
		//点击发布按钮
		//driver.findElement(By.id("rte-button-publish")).click();
	} catch (Exception e) {
		logger.error("exception-" + table.getTableName(), e);
	}
}
driver.close();
DBUtil.closeConn();

running exception info.

Caused by: org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Build info: version: '2.49.1', revision: '808c23b0963853d375cbe54b90bbd052e2528a54', time: '2016-01-21 09:37:52'
System info: host: 'DESKTOP-RHNIR30', ip: '10.7.242.80', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_67'
Driver info: driver.version: unknown
	at <anonymous class>.fxdriver.preconditions.visible(file:///D:/apache-tomcat-7.0.64/temp/anonymous912190740134287098webdriver-profile/extensions/[email protected]/components/command-processor.js:10003)
	at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///D:/apache-tomcat-7.0.64/temp/anonymous912190740134287098webdriver-profile/extensions/[email protected]/components/command-processor.js:12540)
	at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///D:/apache-tomcat-7.0.64/temp/anonymous912190740134287098webdriver-profile/extensions/[email protected]/components/command-processor.js:12557)
	at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///D:/apache-tomcat-7.0.64/temp/anonymous912190740134287098webdriver-profile/extensions/[email protected]/components/command-processor.js:12562)
	at <anonymous class>.DelayedCommand.prototype.execute/<(file:///D:/apache-tomcat-7.0.64/temp/anonymous912190740134287098webdriver-profile/extensions/[email protected]/components/command-processor.js:12504)
2016-01-25 16:04:37,292 ERROR (com.manyi.iw.test.sth.service.impl.WikiServiceImpl:99) - exception-iw_sale_contract_customer_doc
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 16 milliseconds
Build info: version: '2.49.1', revision: '808c23b0963853d375cbe54b90bbd052e2528a54', time: '2016-01-21 09:37:52'
System info: host: 'DESKTOP-RHNIR30', ip: '10.7.242.80', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_67'
Session ID: 413945ea-a8db-4b69-9f34-3868c540174d
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=43.0.4}]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
	at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
	at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
	at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:122)
	at com.manyi.iw.test.sth.service.impl.WikiServiceImpl.autoPublishWiki(WikiServiceImpl.java:88)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
	at com.manyi.iw.test.sth.interceptor.ExceptionInterceptor.invoke(ExceptionInterceptor.java:21)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

exception occured not always, sometiems.

it occured when a button click for a new page but loading, chrome driver can't find the new page document, an exception occured.

how to running complete without firefoxdriver exception. help me, please.

2 Answers 2

1

Try to use explicit wait with expected conditions

WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id"));
element.click();

This will wait up to 20 seconds for the element to be visible. After that the element will be visible and you shouldn't have problem interacting with it.

Sign up to request clarification or add additional context in comments.

3 Comments

hey, guy. another question, how to know an ajax action excute complete in the same page? now, exception occued sometimes, less than ago. i guess it occured when i get the element in a pannel visible, the panel visible after an ajax action complete.
@C.Ke I'm not familiar with ajax, take a look at this
Okay, i see. i try to use another method. thank you.
0

For ajax calls (question asked in the other answer thread), if a loading indicator is displayed while waiting for data, you can wait for the loading indicator to be not visible.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.