点击sedium python td / td部分下的链接

时间:2016-04-20 08:22:38

标签: python selenium

我正在从网页上读表,其中一个列中有一个链接。表格如下:

</div>
<div class="separator"></div>
<h1>User Management:</h1>
<table>
   <tbody>
      <tr>
         ...
      </tr>
      <tr>
         <td>Johnny@gmail.com</td>
         <td>Johnny</td>
         <td><a class="pointer" onclick="deleteUs('http://localhost/..');">button1</a>
            |<a class="pointer" onclick="resetPas('http://localhost/..');">button2</a>
            |<a href="http://localhost/something/something">button3</a>
         </td>
      </tr>
      <tr>
      </tr>`

我想点击button3(在此表的每一行中找到),它会将页面重定向到上面提到的href(http://localhost/something/something) 我该怎么办?

3 个答案:

答案 0 :(得分:1)

请尝试使用find_element_by_partial_link_text()方法。

    element = driver.find_element_by_partial_link_text('Jhonny')

希望它有所帮助。

谢谢。

答案 1 :(得分:0)

select = Select(driver.find_element_by_xpath("//table//td//a[@class!='pointer']"))
select.click()

select = Select(driver.find_element_by_xpath("//table//td//a[3]"))
select.click()

答案 2 :(得分:0)

以下是单击具有单元格“Johnny”的行的链接的示例:

driver.find_element_by_xpath("//tr[td='Johnny']//a[@href]").click()