Python 在 Table 条件中单击 Link

Python Splinter Click Link in Table Conditional

鉴于此("sleep" 方法是为了让您看到我在看什么):

from splinter import Browser
import time
#from selenium.webdriver.support.ui import WebDriverWait
#from selenium.webdriver.remote.webdriver import WebDriver

with Browser() as browser:
    # Visit URL
    url = "https://mdoe.state.mi.us/moecs/PublicCredentialSearch.aspx"
    browser.visit(url)
    browser.fill('ctl00$ContentPlaceHolder1$txtCredentialNumber', 'IF0000000262422')

    # Find and click the 'search' button
    button = browser.find_by_name('ctl00$ContentPlaceHolder1$btnSearch')
    # Interact with elements
    button.first.click()
    #implicitly_wait(time_to_wait=5)
    time.sleep(30)

我希望 Splinter/Selenium 单击右列中对应于左列(同一行)中的值 "Professional Teaching Certification Renewal" 的 link。

这是我到目前为止(在上面的代码之后)尝试过的方法:

tables=browser.find_by_tag('table') #Get all tables
rows=tables.find_by_tag('tr') #Get all rows in the tables
data=rows.find_by_tag('td') #Get the data(cell)s in the rows

我的策略是找到具有值(数据)"Professional Teaching Certification Renewal" 的行,然后对于相应的行,单击右列中的 link。我不确定是否有更好的策略,但如果有的话,我肯定不会嫁给这个。

我无法弄清楚(在阅读文档之后,当然,除非我遗漏了什么)如何检查数据对象并确定它包含的内容。 如果我能做到这一点,我也许就能想出剩下的。

提前致谢!

因为据我了解,您事先知道 Professional Teaching Certificate Renewal 文本并且可以使用它来定位下一列中的 link,我们可以首先通过以下方式定位 td text 然后继续 next sibling td 元素抓住内部 link:

certificate_link = browser.find_by_xpath("//td[. = 'Professional Teaching Certificate Renewal']/following-sibling::td/a") 
certificate_link.first.click()