python - 如何获取属性等到Firefox Selenium,python,window,版本:67.0(64位)+ selenium 3.9.0中的状态变化
问题描述
想确认数据下载是否完成。
目标属性信息如下:
<richlistitem class="download download-state" active="true"
orient="horizontal"
onclick="DownloadsView.onDownloadClick(event);" state="1"
exists="true" selected="true">....<description
class="downloadDetails downloadDetailsHover" crop="end"
value="49.5 KB — xxx.com:8080 — 8:09 PM"/><description
class="downloadDetails downloadDetailsButtonHover"
crop="end"/></vbox></hbox><toolbarseparator/><button
class="downloadButton downloadIconShow"
oncommand="DownloadsView.onDownloadButton(event);"
tooltiptext="Open Containing Folder"/></richlistitem>
# Current script:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://stackoverflow.com/")
download_CSV =dr.find_element_by_id('xxxx')
download_CSV.click()
NEW_TAB = driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
cur_windows = driver.window_handles # NEW TAB
time.sleep(2)
driver.switch_to.window(cur_windows[1])
driver.get('about:downloads')
# EC.until the download message attribute change script
如何获取state="1"的属性(1=表示下载完成,0=还没有)或者exist="true",需要等到state="1"从"0"/orexist="true" “ 出现 ? (欢迎使用其他方法定义文件已经完成下载)
无法将此答案应用于我的情况。 Selenium:等到属性值改变
解决方案
我不知道这是否可行,但也许您可以尝试使用预期条件:presence_of_element_located。
如果网站中没有其他元素响应 Xpath 定位器
//richlistitem[@state='1']
也许这可以解决您的问题:
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//richlistitem[@state="1"]')))
此代码将在 10 秒内查找元素“//richlistitem[@state='1']”,直到该元素位于 DOM 上,否则将返回 TimeoutException
推荐阅读
- flutter - 如何获取存储在 Firebase 中的视频的公共链接
- flutter - 如何让我的主题数据延续到 Flutter 中的新页面
- react-bootstrap - 克隆存储库后在 React-bootstrap 中的测试失败
- postgresql - 按周计算 2 个月内的条目数
- java - PreferenceFragment 在活动重新创建时消失
- python - 为什么它在 API 请求后抛出“KeyError”?
- odoo - odoo 创建产品时我得到的记录不存在或已被删除。(记录:account.account(5913,),用户:104)
- php - 如何在 laravel 中获取 http 请求详细信息?
- go - fork/exec /usr/bin/sudo:无效参数:syscall.CLONE_NEWUSER 导致无效参数错误
- mysql - 应用程序中发生错误,无法提供您的页面将 Node.Js REST 部署到 heroku