簡體   English   中英

如何獲取屬性,直到Firefox Selenium中的狀態更改,python,window,版本:67.0(64位)+ selenium 3.9.0

[英]How to get attribute wait until the state change in Firefox Selenium, python ,window , version : 67.0(64-bit) + 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 =尚未)或存在=“ true”,需要等到state =“ 1”從“ 0”更改為或存在=“ true”出現了嗎? (歡迎使用其他方法定義文件已經完成下載)

無法將此答案應用於我的情況。 硒:等待直到屬性值更改

我不知道這是否行得通,但也許您可以嘗試使用“預期條件”: presentation_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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM