2015-11-02 112 views
0

我正在嘗試使用selenium webdriver python自動化某些東西。我在這樣做的過程中取得了部分成功。我在兩者之間嶄露頭角。無法通過硒python來單擊表中的超鏈接

<td role="gridcell" style="" title="6563378117093014222" aria-describedby="devices_x1AccountId"> 
 
    <a href="accountSummary?accountId=6563378117093014222">6563378117093014222</a> 
 
</td>

我試圖單擊表描述符中的超級鏈接,但它顯示出一些錯誤。

這裏是我的代碼:

deviceID = browser.find_elements(By.XPATH, "//*[@aria-describedby= 'devices_billingId']/a") 
deviceID.click() 

我不知道我做錯了。請提出一些解決的find_elements

+0

什麼樣的錯誤你得到? – Sighil

+0

@Rajesh你可能會搜索錯誤的詠歎調描述 - >看我更新的答案 – drkthng

+0

@drkthng它的錯字。即使我有另一種場景,我正在使用'devices_x1AccountId'。 – Rajesh

回答

2

使用find_element代替然後在您的XPath您正在搜索「devices_billingId」,但在你的代碼中的唱段,describedby是「devices_x1AccountId」

deviceID = browser.find_element_by_xpath("//*[@aria-describedby= 'devices_x1AccountId']/a") 
deviceID.click() 
+0

AttributeError:'list'對象沒有'click'屬性。我嘗試使用find_element以及它不工作:( – Rajesh

+1

@Rajesh,'find_element'應該返回一個'WebElement',而不是'list'。你做的事情是錯誤的。@drkthng絕對正確 – sircapsalot

+0

我得到錯誤「無法找到元素「後,將其更改爲find_element – Rajesh