51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 856|回复: 0
打印 上一主题 下一主题

请问这个登录脚本错哪了?确实是定位问题吗?该怎么解决?

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2015-5-8 17:34:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
-----------------------------------------脚本----------------------------------------------------------------------------------------
public class day05 {
        WebDriver driver;
        public void startFire(){
                System.setProperty("webdriver.firefox.bin", "C:\\Z_firefox_browser_32_0_3\\firefox.exe");
                driver=new FirefoxDriver();
        }
        public void goTo(){
                driver.navigate().to("http://192.168.1.110:8888/fsasit");
        }

        public void testInput(){
                driver.findElement(By.id("loginname")).sendKeys("admin");
                driver.findElement(By.xpath(".//*[@id='password']")).sendKeys("1");
        }
        public void testButton(){
                WebElement element=driver.findElement(By.name("Image10"));
                if(element.isEnabled()){
                        element.click();
                }
        }
        public static void main(String[] args) {
                day05 d=new day05();
                d.startFire();
                d.goTo();
                d.testInput();
                d.testButton();
        }
}

---------------------------------------------------------------报错---------------------------------------------------------------------------------------------------------------
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"loginname"}
Command duration or timeout: 1.11 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'asit-f226940e7c', ip: '192.168.1.128', os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_27'
*** Element info: {Using=id, value=loginname}
Session ID: 276583ff-0f65-49ec-b8a1-958afb617151
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=32.0.3, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, nativeEvents=false, 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.findElementById(RemoteWebDriver.java:393)
        at org.openqa.selenium.By$ById.findElement(By.java:214)
        at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
        at com.woo.www.day05.testInput(day05.java:29)
        at com.woo.www.day05.main(day05.java:50)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"loginname"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'asit-f226940e7c', ip: '192.168.1.128', os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_27'
Driver info: driver.version: unknown
        at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/anonymous1499355153816007334webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:10271)
        at <anonymous class>.FirefoxDriver.prototype.findElement(file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/anonymous1499355153816007334webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:10280)
        at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/anonymous1499355153816007334webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12274)
        at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/anonymous1499355153816007334webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12279)
        at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/anonymous1499355153816007334webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12221)



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-8 01:41 , Processed in 0.063227 second(s), 24 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表