|
5#
楼主 |
发表于 2012-8-20 17:04:56
|
只看该作者
代码:
- WebDriver driver = new InternetExplorerDriver();
- driver.get("http://127.0.0.1:8080/sys");
- System.out.println("Page title is: " + driver.getTitle());
- WebElement element_usr = driver.findElement(By.name("loginName"));
- element_usr.sendKeys("testuser");
- WebElement element_pwd = driver.findElement(By.name("loginPwd"));
- element_pwd.sendKeys("testpwd");
复制代码
这样运行是正常的.
但如果把第二行换成driver.get("http://192.168.99.8:8080/sys"); 就不行. 打开登录页面然后就不动了.提示无法找到元素.
错误提示:
org.openqa.selenium.NoSuchElementException: Unable to find element with name == loginName (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 297 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.21.0', revision: '16552', time: '2012-04-11 19:09:00'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_13'
Driver info: driver.version: RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:175)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:459)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:227)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:288)
at org.openqa.selenium.By$ByName.findElement(By.java:292)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:219)
at com.huawei.seleniumtest.testdriver.driver.testDriver(driver.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) |
|