我想找到屬性爲$ 9a的元素,但顯然美元符號導致問題。當我使用表達式:Escape Selenium xpath locator中的美元符號
//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查詢嗎?也許你可以避免'$' – olyv 2014-11-21 13:08:03
你能顯示它的html部分嗎? – 2014-11-21 13:45:58
我已經創建了一個解決方法,但我仍然想以某種方式使用此屬性。 – Danio 2014-11-21 14:22:49