无法在IE中找到使用CSSpath的元素,尽管与使用Java的Selenium WebDriver的FF相同

时间:2013-04-17 12:20:36

标签: java selenium-webdriver

以下是我在IE中使用的代码的语法:

driver.findElement(By.cssSelector("#loginForm>div>table>tbody>tr:nth-child(4)>div>span>span>span")

错误是:

org.openqa.selenium.NoSuchElementException: Unable to find element with css selector == #loginForm>div>table>tbody>tr:nth-child(4)>div>span>span>span (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 594 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_17'
Session ID: f0058b48-ac08-4623-9920-5a871ce43605
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, elementScrollBehavior=0, javascriptEnabled=true, enablePersistentHover=true, ignoreZoomSetting=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=8, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, allowAsynchronousJavaScript=true, requireWindowFocus=false, handlesAlerts=true, initialBrowserUrl=, nativeEvents=true, takesScreenshot=true}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

正如其他人所说,CSS3选择器无法在IE8或更低版本上运行,例如nth-child

我在这样的时间看下面的网站,看看支持什么和什么不支持:

http://caniuse.com/#search=nth-child

至于下一步,我会做两件事:

运行最新版本的Selenium。

将您的定位器更改为类似的内容(未经过测试,因为您没有提供HTML):

//*[@id='loginForm']/div/table/tbody/tr[4]/div/span/span/span

答案 1 :(得分:-1)

The Html code is as follows.
<form name="loginForm" id="loginForm" action="/suredesign/j_spring_security_check" method="post">
<div class="dijitLayoutContainer dijitContainer dijitTableLayout" id="dojox_layout_TableContainer_0" data-dojo-props="cols:1,spacing:10,showLabels:false" data-dojo-type="dojox.layout.TableContainer" widgetId="dojox_layout_TableContainer_0">
<table width="100%" class="tableContainer-table tableContainer-table-horiz" cellSpacing="10">
<tbody>
<tr>
<tr>
<tr>
<tr>
<td class="tableContainer-valueCell">
<div title="" class="dijitContentPane" id="dijit_layout_ContentPane_17" role="group" data-dojo-type="dijit.layout.ContentPane" widgetId="dijit_layout_ContentPane_17">
<span class="dijit dijitReset dijitInline dijitButton paddingright5 signInLabel" role="presentation" widgetId="dijit_form_Button_0">
dijitReset dijitInline dijitButtonNode