2016-05-15 62 views
-1

我們都知道通過使用.text來找到元素中存在的文本。如何使用Python中的Selenium Webdriver從文本中獲取元素

現在,如果我有文本,我該如何找到元素。

例:

<a class="user" href="/profile/Philip-Nunn-2" action_mousedown="UserLinkClickthrough" id="__w2_hN4ZuPR_link" target="_blank">Philip Nunn</a> 

這裏我有Philip Nunn我,所以我怎麼能得到這個信息元素的標籤?

回答

1

你可以嘗試一個xpath爲此。

'//a[contains(., "{}")]'.format(text) 

這將定位包含text

+0

你是如何得到這一點,因爲我無法找到任何w3school這樣的事情,可以請你轉發我的任何鏈接錨標記。 – Arkham

相關問題