Python Splinter 单击表条件中的链接

标签 python selenium splinter

鉴于此(“ 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 单击右列中与左列(同一行)中的值“专业教学认证续订”相对应的链接。

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

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

我的策略是找到具有值(数据)“专业教学认证续订”的行,并针对该相应行,单击右列中的链接。我不确定是否有更好的策略,但如果有的话我肯定不会选择这种策略。

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

提前致谢!

最佳答案

据我了解,由于您事先知道专业教学证书更新文本,并且可以使用它来定位下一栏中的链接,因此我们可以首先找到td 通过文本,然后继续到 next sibling td 元素抓取内部链接:

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

关于Python Splinter 单击表条件中的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47971823/

相关文章:

javascript - 使用 Splinter 查找按钮

python - Splinter 拯救无形的 html

python - Jinja2 中如何将变量从一个模板传递到另一个模板

python - 保持 ConfigParser 输出文件排序

ruby-on-rails - Ruby selenium webdriver 无法找到 Mozilla geckodriver

java - 带有 Selenium Java 的剑道组合框

python - 收到 DistributionNotFound 错误,但包存在

python - Pandas 将多个 csv 值分配给单个数据框列中的列表

python - Selenium 不打印文本