I want to wait for a page to finish converting a json file, then automatically download it. The following python code works.
import time
from selenium import webdriver
chrome = webdriver.Chrome()
chrome.get('https://json-csv.com/')
load_data = chrome.find_element_by_id('fileupload')
load_data.send_keys('C:\\path_to_file')
load_data.submit()
# Wait arbitrary duration before downloading result
time.sleep(10)
get_results = chrome.find_element_by_id('download-link')
get_results.click()
chrome.quit()
However, every time I run the script, I need to wait 10 seconds, which is more than enough for the page to finish converting the file. This is not time efficient. The page may finish loading the new file in 5 seconds.
How can I click the download button the moment the file is done converting?
What I've tried
I've read a solution to a similar problem, but it threw an error: ElementNotVisibleException: Message: element not visible.
Also tried following the documentation example:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
...
wait = WebDriverWait(chrome, 10)
get_result = wait.until(EC.element_to_be_clickable((By.ID, 'download-link')))
get_result.click()
This downloads some nonsense .tmp
file instead.