2014-01-16 60 views
1
<div class="myclass">  
<a href="example.com" class="link" content="This is my content" </a> 
</div> 

使用硒(Python),我想要找到content的值。我嘗試使用find_element_by_tag_name,但它似乎不工作。如何在使用Selenium的另一個標籤內找到自定義標籤

+0

它不起作用,因爲'content'不是_element/tag_。它是''a'元素/標籤上的_attribute_。 –

回答

5
find_elements_by_xpath('//div[@class="myclass"]/a').get_attribute("content") 
+0

謝謝。我剛剛瞭解到最簡單的方法是使用Chrome Developer工具檢查元素並複製XPath – Cory

1
find_elements_by_css_selector('div.myclass > a').get_attribute('content') 

這比XPath的乾淨多了。 CSS比xpath更快,更易讀。我建議使用這個。

相關問題