【发布时间】:2022-01-24 15:08:21
【问题描述】:
我正在尝试单击按钮来启动文件下载。该按钮具有我所看到的悬停功能。我试过点击全部find_element_by paths。
页面的 HTML 块,
<button class="btn-retrieve ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="sub_1:listPgFrm:j_idt6461:downloadBtn" name="sub_1:listPgFrm:j_idt6461:downloadBtn" onclick="new ice.ace.DataExporter('sub_1:listPgFrm:j_idt6461:downloadBtn', function() { ice.ace.ab(ice.ace.extendAjaxArgs({"source":"sub_1:listPgFrm:j_idt6461:downloadBtn","execute":'@all',"render":'@all',"event":"activate","onstart":function(cfg){showProcessingMessage('Downloading'); return true;;}}, {node:this})); });return false;" style="margin-top: -4px;" role="button" aria-disabled="false"><span class="ui-button-text"><span>Download</span></span></button>
悬停前按钮的类是,
"btn-retrieve ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
悬停时按钮的类是,
"btn-retrieve ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-state-hover"
通过开发者窗口选择按钮并复制路径
<span>Download</span>==$0
我得到以下信息,
CSS 路径,
#sub_1\:listPgFrm\:j_idt6461\:downloadBtn > span > span
XPath,
//*[@id="sub_1:listPgFrm:j_idt6461:downloadBtn"]/span/span
我尝试过的代码,
dwnd = driver.find_element_by_xpath("//*[@id='sub_1:listPgFrm:j_idt6461:downloadBtn']/span")
dwnd.click()
还有,
button = driver.find_element_by_css_selector("#sub_1\:listPgFrm\:j_idt6461\:downloadBtn")
download = driver.find_element_by_link_text("Download")
hover = ActionChains(driver).move_to_element(button).move_to_element(download)
hover.click().build().perform()
【问题讨论】:
-
可以提供网址吗?
-
你至少可以分享页面 HTML 吗?不是单个元素而是整个页面?
-
我明白了。我不确定我能做些什么。也许其他人可以
标签: python selenium selenium-webdriver web-scraping selenium-chromedriver