首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >需要单击与给定文本匹配的下载按钮。

需要单击与给定文本匹配的下载按钮。
EN

Stack Overflow用户
提问于 2020-10-05 18:17:49
回答 1查看 59关注 0票数 1

我正在尝试下载发票,它的税务发票写在表中,我在表元素中迭代并获取所需的详细信息。但是当我点击“下载”按钮时,它会下载两次相同的发票。如何让它下载第二张“税务发票”?下图如下:

以及html代码:

下面是代码:

代码语言:javascript
复制
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC




driver = webdriver.Chrome(executable_path=r'D:/Chrome driver/chromedriver.exe')
driver.get("the link")

time.sleep(10)

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="GST"]/div/div/a[2]/span[1]'))).click()

driver.switch_to.frame('ifgstdownloadnFrame')
driver.find_element_by_xpath('//*[@id="txtpnr"]').send_keys('QYJ27J')

driver.find_element_by_xpath('//*[@id="btnSubmit"]').click()

mytable = driver.find_element_by_css_selector("table.gstInvoiceGrid")

for row in mytable.find_elements_by_css_selector('tr'):
    for cell in row.find_elements_by_tag_name('td'):
        if 'Tax Invoice' in cell.text:
            print()
            driver.find_element_by_css_selector('input.download.downloadbutton').click()
time.sleep(10)
            
#driver.quit()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-05 19:02:56

您需要通过使用intermediate来更改查找dot单元格的逻辑,使用以下代码逻辑之一,它将单击具有Tax Invoice的每个下载按钮。

代码语言:javascript
复制
for row in mytable.find_elements_by_css_selector('tr'):
    for cell in row.find_elements_by_xpath('./td'):
        if 'Tax Invoice' in cell.text:
            print()
            row.find_element_by_xpath(".//input[@value='Download']").click() 

代码语言:javascript
复制
for row in mytable.find_elements_by_css_selector('tr'):
    if row.find_element_by_xpath("./td[text()='Tax Invoice']"):
        row.find_element_by_xpath(".//input[@value='Download']").click()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64214095

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档