Python Splinter单击表条件中的链接

问题描述 投票:1回答:1

鉴于此(“睡眠”方法是这样你可以看到我正在看的东西):

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点击右栏中与“专业教学认证续订”值相对应的链接,该栏目位于左侧(同一行)的栏目中。

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

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”的行,并且对于该对应的行,单击右列中的链接。我不确定是否有更好的策略,但如果有的话,我肯定不会和这个人结婚。

我无法弄清楚(在阅读文档之后,当然,除非我遗漏了什么)如何检查数据对象并确定它包含的内容。如果我能做到这一点,我或许可以弄明白其余的事情。

提前致谢!

python selenium splinter
1个回答
1
投票

因为,根据我的理解,您事先知道Professional Teaching Certificate Renewal文本并可以使用它来定位下一列中的链接,我们可以首先通过文本找到td然后继续到next sibling td元素抓取内部链接:

certificate_link = browser.find_by_xpath("//td[. = 'Professional Teaching Certificate Renewal']/following-sibling::td/a") 
certificate_link.first.click()
© www.soinside.com 2019 - 2024. All rights reserved.