selenium - 如何通过 Selenium 和 Python 根据 URL 单击带有文本的按钮作为导出?
问题描述
我被困住了,我很想得到你的帮助。我不是 Python 天才,所以为这门语言道歉。我需要单击此网站https://www.fec.gov/data/filings/?data_type=processed&committee_id=C00097485上的按钮(导出) 。该按钮应驱动到出现 Excel 文件链接的页面底部。现在,我使用了这段代码:
text="//button[@type='button' and contains(.,'Export')]"
driver = webdriver.Firefox()
driver.get("https://www.fec.gov/data/filings/data_type=processed&committee_id=C00142711")
time.sleep(5)
button=driver.find_element_by_xpath(text)
button.click
脚本运行良好,没有错误消息。该网站出现,但没有发生“点击”。我也尝试过:1)“等待驱动程序直到元素可点击”,2)ActionChain 移动光标,3)用 sendKeys 替换点击。没有 iframe。我也在 Chrome 上试过。我正在使用装有 Windows 10 的电脑。
我究竟做错了什么???考虑到其他网站,点击功能非常好!
解决方案
Click 是一种方法,所以它应该是button.click()
。你缺少括号。
此外,如果您使用WebDriverWait
而不是会更好.sleep()
,例如button = WebDriverWait(driver, 20).until( EC.element_to_be_clickable((By.XPATH, text)));
推荐阅读
- authentication - 在 Linux 下使用 curl 到 FTPS 到 z/OS FTP TLS 服务器与客户端身份验证
- javascript - render() 是如何实际执行的?
- blazor - Mapster 和 Blazor
- build - Bamboo 构建后自动删除工件的脚本
- java - 如何在@PostConstruct 方法中测试@Override 方法
- python - pandas 中的正则表达式用 ^ 过滤列
- javascript - 当我需要访问变量时,如何不使用 arguments.callee?
- jquery - ASP.NET 5 MVC 使用 jQuery 显示和隐藏 div 元素
- scroll - 如何制作滚动时不移动的固定标题?
- r - 如何在 r 中的第三个映射表的帮助下连接两个表?