我在selenium webdriver 2.0中工作,我必须自动化一个脚本来运行功能和跨浏览器测试。当我尝试点击类element not visible
的元素进行下拉时,我收到.divAdvSearchFeildListName&[data-id='30001']
的错误。
相同的代码适用于某些下拉菜单,以便从同一页面上的同一页面中选择国家/地区名称和辖区。我得到的错误是:
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 47 milliseconds
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:22:56'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_21'
Session ID: 2ca283f6-5703-4ef6-b07f-2dee99b531ab
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}]
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:187)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79)
at com.anteambulo.SeleniumJQuery.Prog_Try_Six.automate(Prog_Try_Six.java:1112)
at com.anteambulo.SeleniumJQuery.Prog_Try_Six.hCueIgn(Prog_Try_Six.java:122)
at com.anteambulo.SeleniumJQuery.Prog_Try_Six.main(Prog_Try_Six.java:71)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Element is not currently visible and so may not be interacted with
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:22:56'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_21'
Driver info: driver.version: unknown
at <anonymous class>.fxdriver.preconditions.visible(file:///C:/DOCUME~1/155366/LOCALS~1/Temp/anonymous8998336689581680973webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:7682)
at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///C:/DOCUME~1/155366/LOCALS~1/Temp/anonymous8998336689581680973webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10402)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/DOCUME~1/155366/LOCALS~1/Temp/anonymous8998336689581680973webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10421)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/DOCUME~1/155366/LOCALS~1/Temp/anonymous8998336689581680973webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10426)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/DOCUME~1/155366/LOCALS~1/Temp/anonymous8998336689581680973webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10366)
我的代码卡在此代码段中的第6行。正如你在代码中看到的那样,我试图突出显示带有5px
纯黄色边框的web元素:
jQuery EntitySearchTypeValue = browser.queryUntil(a1ValEntityDropDownList);
setCellName(26,0,a1ValEntityDropDownListLabel,sheetReportGeneration);
hCueExcel(1,1,26,sheetReportGeneration,browser,colNoForDiffBrowsers,EntitySearchTypeValue);
System.out.println("Login Button found");
// password.css("border", "none");
EntitySearchTypeValue.css("border", "5px solid yellow");
takescreenshot(a1ValFileNamePath,26,colNoForDifferentScreenShots,sheetSnapshotGeneration,workbook);
***EntitySearchTypeValue.get().click();***
// browser.findElement(By.className("divAdvSearchFeildListName&[data-id='30001']")).click();
// browser.getDrv().findElementByClassName("EntitySearchTypeValue&[data-id='30001']").click();
// browser.getDrv().findElementByCssSelector(".divAdvSearchFeildListName&[data-id='30001']").click();
// document.querySelector(".field[data-test]");
// browser.get()
// By cssSelector = By.cssSelector(".field[data-test='testytest']");
// or By.cssSelector(".field[data-test=testytest]")
// or By.cssSelector(".field[data-test]")
//bin.findElement(cssSelector).sendKeys("Hello");
try{
Thread.sleep(5000L);
}catch(Exception e){
}
相同的代码在Firefox中运行良好,但稍后在其他浏览器的代码中陷入困境。对于Chrome,它会在同一页面的第三个下拉列表中停滞不前。我有selenium-server-standalone-2.32.0.jar
这是最新版本。
答案 0 :(得分:0)
此异常表示您尝试单击的元素被隐藏。在单击之前确保元素可见。如果元素在延迟后变得可见,您可以添加等待。
除此之外,你应该检查系统配置,它应该是兼容的。