无法在IE中找到具有CSSpath的元素,尽管与Java的Selenium WebDriver的FF一起工作很好



以下是我在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)
有谁能帮帮忙吗?

正如其他人所说,CSS3选择器无法在IE8或以下版本上工作,例如nth-child

在这种情况下,我会查看下面的站点,看看哪些是支持的,哪些是不支持的:

http://caniuse.com/搜索= nth-child

下一步,我将做两件事:

运行最新版本的Selenium.

将您的定位器更改为以下内容:

//*[@id='loginForm']/div/table/tbody/tr[4]/div/span/span/span
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

最新更新