51Testing软件测试论坛
标题: selenium代码调试正常运行报错 [打印本页]
作者: 雨弦扬 时间: 2015-6-16 17:01
标题: selenium代码调试正常运行报错
代码在调试的时候,跳转正常;但是在运行的时候,登录进来之后就之刷新当前页面而且后台报错:org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for EOMSPROJ2.BBZL_catogory$2@2719f1f
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'WIN-15M674MHPEV', ip: '169.254.213.92', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_45'
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:259)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:228)
at EOMSPROJ2.BBZL_catogory.testUntitled(BBZL_catogory.java:162)
at EOMSPROJ2.BBZL_catogory.rootToAdd(BBZL_catogory.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"link text","selector":"表报资料类别管理"}
Command duration or timeout: 30.46 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'WIN-15M674MHPEV', ip: '169.254.213.92', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_45'
Session ID: f6640b1a-a8b6-45d8-abb4-89643328e1ca
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=29.0.1, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:401)
at org.openqa.selenium.By$ByLinkText.findElement(By.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
at EOMSPROJ2.BBZL_catogory$2.apply(BBZL_catogory.java:167)
at EOMSPROJ2.BBZL_catogory$2.apply(BBZL_catogory.java:1)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
... 27 more
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"link text","selector":"表报资料类别管理"}
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'WIN-15M674MHPEV', ip: '169.254.213.92', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_45'
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous2995113652113805500webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:9470)
at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous2995113652113805500webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:407)
================================================================================================
本人的代码如下:
==============================================================================
package EOMSPROJ2;
import java.util.Random;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
public class BBZL_catogory {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
System.setProperty("webdriver.firefox.bin","D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
driver = new FirefoxDriver();
baseUrl = "http://localhost:8090/zxflow";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
@Test
public void noChoiceToAdd() throws Exception {
testUntitled();
driver.findElement(By.cssSelector("span.menu-text")).click();
driver.findElement(By.cssSelector("strong")).click();
driver.findElement(By.cssSelector("span.l-btn-text")).click();
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
//*******************************跳转代码主要在这里跳不了****************************************************//
private void testUntitled() throws Exception {
driver.get(baseUrl);
driver.findElement(By.name("loginid")).clear();
driver.findElement(By.name("loginid")).sendKeys("jichen");
driver.findElement(By.name("loginpass")).clear();
driver.findElement(By.name("loginpass")).sendKeys("1");
driver.findElement(By.cssSelector("img")).click();
//**以下的代码没有没有发生跳转**//
WebElement e =(new WebDriverWait( driver,500)).until(
new ExpectedCondition< WebElement>(){
@Override
public WebElement apply( WebDriver d) {
return d.findElement(By.linkText("表报资料"));
}
}
);
e.click();
WebElement a = (new WebDriverWait( driver, 10)).until(
new ExpectedCondition< WebElement>(){
@Override
public WebElement apply( WebDriver d) {
//return d.findElement(By.cssSelector("span.menu-text"));
return d.findElement(By.linkText("表报资料类别管理"));
}
}
);
a.click();
}
}
作者: tiankai30 时间: 2015-6-17 09:37
Unable to locate element: {"method":"link text","selector":"表报资料类别管理"}
换个方法 加长等待时间 试试
作者: macg1987 时间: 2015-9-2 16:46
apply( WebDriver d) 这里的webdriver是没有实例化的driver,怎么可能会跳转呢?应当ref driver
作者: a9966 时间: 2015-9-18 09:13
作者: dragondl2015 时间: 2015-9-21 14:52
还严重bug,这是你的bug吧,还报别人bug!!!
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) |
Powered by Discuz! X3.2 |