简体   繁体   中英

How to get attribute wait until the state change in Firefox Selenium, python ,window , version : 67.0(64-bit) + selenium 3.9.0

Want to confirm whether the data downloading is finished .

The target attributes information like below :

<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

How to get the attribute of state="1" (1 =meaning download finished,0=not yet) or exist="true",need to wait until state="1" changed from "0" / or exist="true" appear ? (welcome for other method the define the file is already finished download)

Cannot apply this answer to my situation. Selenium : wait until attribute value changed

I dont know if this will work but maybe you can try with the Expected conditions: presence_of_element_located .

If there is no other element in the website that responds to the Xpath locator

//richlistitem[@state='1']

Maybe this can be the sollution to your problem:

WebDriverWait(driver, 10).until(
                EC.presence_of_element_located((By.XPATH, '//richlistitem[@state="1"]')))

This code will be looking for the element "//richlistitem[@state='1']" during 10 seconds until the element is located on the DOM otherwise it will return TimeoutException

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM