如何让firefoxdriver正常不出错地跑完整个内容提交流程

kehui 2016-01-25
我做了个自动发布wiki的工具,其它功能都是没有问题的。单单在firefoxdriver这里,firefox在从当前页面跳到另外一个页面的时候,报错。

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("这里是用户名");
                    driver.findElement(By.id("os_password")).sendKeys("这里是密码");
                    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();


发现睡了也没什么用。有没有遇到过这样问题的,举个手,说下解决办法?
kehui 2016-01-25
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: '', 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/fxdriver@googlecode.com/components/command-processor.js:10003)
	at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///D:/apache-tomcat-7.0.64/temp/anonymous912190740134287098webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12540)
	at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///D:/apache-tomcat-7.0.64/temp/anonymous912190740134287098webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12557)
	at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///D:/apache-tomcat-7.0.64/temp/anonymous912190740134287098webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12562)
	at <anonymous class>.DelayedCommand.prototype.execute/<(file:///D:/apache-tomcat-7.0.64/temp/anonymous912190740134287098webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12504)
2016-01-25 16:04:37,292 ERROR (WikiServiceImpl:99) - exception-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)

 

以上是报错信息

DanaChen 2016-02-25
你new FirefoxDriver()的时候需要加入驱动
Global site tag (gtag.js) - Google Analytics