1
我使用硒webdriver單擊鏈接,但它會拋出NoSuchElementException。我使用的發現,當我執行瀏覽器搜索在檢查元素選項卡中選擇所需的鏈接的XPath,還當我在瀏覽器中執行下面的javascript - 控制檯,鏈接被點擊擺好,硒沒有點擊一個鏈接,而在JavaScript上,鏈接完美點擊
Javascript代碼:
var element = window.top.document.evaluate("//a[@id='clients']/i[@class='icon-chevron-down']" ,document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;if (element != null) { element.click(); } else { alert('Not Found'); }
但是不知道爲什麼硒拋出下面的異常,我已經嘗試各種明確的等待,然後點擊。
org.openqa.selenium.NoSuchElementException: no such element
(Session info: chrome=42.0.2311.135)
(Driver info: chromedriver=2.9.248307,platform=Mac OS X 10.9.5 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 45.05 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'VDO105.local', ip: '172.16.0.70', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.7.0_75'
Session ID: b9f85e7103119d4c7b7ff265d02187ca
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/var/folders/1v/pyj3pk396pb0z71_tlqcppgh0000gn/T/.org.chromium.Chromium.TePZ9p}, rotatable=false, locationContextEnabled=true, version=42.0.2311.135, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]
這裏是鏈接的html代碼:
<a ng-show="sideBar.length" class="dropdown-toggle toggle-active" id="clients" href="javascript:void(0);">
<i class="icon-group"></i>
<span class="menu-lv-1 ng-binding">Clients</span>
<i class="icon-chevron-down"></i>
</a>