selenium2 用鏈接文本定義超鏈接

2021-07-02 17:05 更新

如果你知道一個(gè)錨標(biāo)簽使用了什么文本,那么就使用這種方法。在超鏈接定位里,會(huì)返回第一個(gè)文本屬性匹配的鏈接,如果沒有元素匹配,會(huì)拋出?NoSuchElementException?異常。

實(shí)例:

<html>
 <body>
  <p>Are you sure you want to do this?</p>
  <a href="continue.html">Continue</a>
  <a href="cancel.html">Cancel</a>
</body>
<html>

可以這樣定位 ?continue.html?鏈接:

continue_link = driver.find_element_by_link_text('Continue')
continue_link = driver.find_element_by_partial_link_text('Conti')
注:?find_element_by_partial_link_text?使用子串匹配,只要輸入子字符串即可匹配。
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)