【发布时间】:2018-09-04 09:41:02
【问题描述】:
我被困住了,我很想得到你的帮助。我不是 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))); -
谢谢!!!! click() 是问题!!!
-
没问题。我已将我的评论添加为答案,如果您想接受它,这样问题就不会无人回答。
标签: selenium selenium-webdriver webdriver webdriverwait