0

以下是我在 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)

有人可以帮忙吗?

4

2 回答 2

0

正如其他人所说,CSS3 选择器不适用于 IE8 或更低版本,例如nth-child.

我会在这样的时间查看以下站点,以查看支持的内容和不支持的内容:

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

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

运行最新版本的 Selenium。

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

//*[@id='loginForm']/div/table/tbody/tr[4]/div/span/span/span
于 2013-04-18T08:59:31.690 回答
-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
于 2013-04-18T13:35:59.147 回答