首页 文章

执行Selenium Web驱动程序脚本时收到错误“元素当前不可见,因此可能无法与之交互”

提问于
浏览
0
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 21 milliseconds
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:22:56'
System info: os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_25'
Session ID: 16492097-714b-42c4-b9dc-2c3979db180f
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=22.0}]

执行脚本的结果不一致 . 有时它会通过,有时它会抛出上面提到的异常 .

2 回答

  • 0

    脚本结果不相同,因为该元素可能会在页面上显示不同的时间 .

    使用睡眠可以解决问题,但这不是一个好的做法,因为如果测试用例即使在睡眠后失败也可能需要调整/增加值 .

    更好地使用等待元素功能 .

    有关详细信息,请参阅文档@“http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

  • 0

    是您需要使用条件等待,以便您的代码将等到它找到元素 .

    例如:如果您使用的是网络驱动程序

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id( “用户名”)));

相关问题