【发布时间】:2015-01-19 13:28:30
【问题描述】:
我想找到一个属性为 $9a 的元素,但显然美元符号引起了问题。当我使用表达式时:
//td[@id='isc_6T']//span[@$9a='browse']
我得到以下异常
The given selector //td[@id='isc_6T']//span[@$9a='browse'] is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: Unable to locate an element with the xpath expression //td[@id='isc_6T']//span[@$9a='browse'] because of the following error:
SyntaxError: The expression is not a legal expression.
Command duration or timeout: 9 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'
System info: host: 'daniel', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-39-generic', java.version: '1.7.0_65'
Session ID: 7fdd584b-10b8-4c5a-ab64-72fe7cff7e2a
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=LINUX, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=33.0}]
编辑: 这是我要查找的 HTML 部分。 (id是动态的,不能直接使用)
<span handlenativeevents="false" $9a="browse" id="isc_T9" role="button">
<img border="0" align="TEXTTOP" height="18" width="18" draggable="true" suppress="TRUE" style="vertical-align:middle;margin-top:0px;margin-bottom:0px;" id="isc_TA" src="some_image.png">
</span>
我已经创建了一个解决方法,使用 Jsoup 解析 HTML 以确定当前的动态 id,但我仍然想要一个更简洁的解决方案
【问题讨论】:
-
有没有办法重写 xpath 查询?也许你可以避免
$ -
你能显示它的html部分吗?
-
我已经创建了一个解决方法,但我仍然想以某种方式使用此属性。
标签: java selenium xpath webdriver