2015-06-11 27 views
0

我正試圖在頁面上找到一個鏈接,然後單擊它。下面是DOM的快照:Element DOM如何對一個元組進行點擊操作?

這是我怎麼想找到它:

try: 
    PublishAPostButton = WebDriverWait(Driver.Instance,30).until(lambda d:Driver.Instance.find_element_by_xpath("//div[@class='articles-actions']/a[starts-with(text(),'Publish a post')]")).is_displayed(), "Link still not exists" 
except: 
    print("Publish a post link not available") 
else: 
    PublishAPostButton.click() 
    print("Publish a post link was clicked") 

「嘗試」塊的執行沒有任何錯誤或異常,但它返回一個元組(不知道爲什麼!)。控制轉到「其他」並嘗試點擊。顯然,它不能單擊一個元組,並因此給出錯誤。這是我得到的錯誤:AttributeError:'元組'對象沒有'點擊'屬性。 我不明白的是它是如何返回一個元組?請幫忙!

回答

3

因爲你的括號關閉是不是在try塊正確,將其更改爲以下:

try: 
    PublishAPostButton = WebDriverWait(Driver.Instance,30).until(lambda d:Driver.Instance.find_element_by_xpath("//div[@class='articles-actions']/a[starts-with(text(),'Publish a post')]")).is_displayed() 
except: 
    print("Publish a post link not available") 
else: 
    PublishAPostButton.click() 
    print("Publish a post link was clicked") 
+0

但Try塊要麼返回真或假。在else塊中,單擊()操作不能在布爾值上執行 –

+0

不,try塊將該元素分配給變量PublishAdPostButton –

相關問題