2012-10-25 141 views
1

我有我試圖通過find_element_by_link_text硒RC蟒蛇,使用find_element_by_link_text

<A href="/help/index.html?sys_optimization_community.html" target="_blank"><IMG src="/images/help.gif" border="0" alt="Help" hspace="3"></A> 

找到正如你可以看到有沒有鏈接的文字下面的HTML元素。我可以使用find_element_by_link_text或者是否有任何其他可以使用的selenium python庫的API。請幫忙。

+0

哪裏是html代碼? – specialscope

+0

感謝@RocketDonkey進行格式化。 – Anand

+0

沒有概率 - 想出有什麼東西:) – RocketDonkey

回答

1

您無法使用find_element_by_link_text。你有3個選項。

  1. 如果你有對html的控制權,可以添加一個id並通過id來獲取它。
  2. 獲取頁面中的所有鏈接並使用具有指定鏈接(href值)的鏈接。
  3. 最好的方法:使用xpath。
+0

我如何獲得頁面中的所有鏈接?另外與xpath是這樣的\ a [@src ='/ images/help。 gif']。當我嘗試使用target = _blank時,我在機器人框架中出現錯誤,提示「無法找到類型」 – Anand

+0

要獲取所有鏈接,請使用findElement(By.tagName(「a」));迭代它。獲取href值使用elem.getAttribute(「href」) – specialscope

+0

Xpath的工作。我會嘗試另一種方法,因爲我們ll ..我試過// TD/a [@ target = _blank]謝謝。 – Anand