I
I
Ivan Yakushenko2019-05-28 15:15:27
Python
Ivan Yakushenko, 2019-05-28 15:15:27

How to download media from Selenium in headless?

thumb = driver.find_elements(By.XPATH, '//*[@class="copyable-area"]//div[contains(@class, "video-thumb")]')
print('1')
try:
    action = ActionChains(driver)
    action.move_to_element(thumb[-1])
    print('2')
    action.perform()
    time.sleep(0.2)
except Exception as e:
    print(e)
try:
    print('3')
    thumb[-1].click()
except Exception as e:
    print(e)
WebDriverWait(driver, 10).until(ec.presence_of_element_located((By.XPATH, '//*[@id="app"]/div/span[3]/div/div/div[2]/div[1]/div[2]/div')))
print('4')
time.sleep(0.2)
dwnld = driver.find_element(By.XPATH, '//*[@id="app"]/div/span[3]/div/div/div[2]/div[1]/div[2]/div/div[4]/div')
print('5')
try:
    action = ActionChains(driver)
    action.move_to_element(dwnld)
    action.perform()
    print('6')
    time.sleep(0.2)
except Exception as e:
    print(e)
try:
    dwnld.click()
    print('7')
except Exception as e:
    print(e)
con_exit = driver.find_element(By.XPATH, '//*[@id="app"]/div/span[3]/div/div/div[2]/div[1]/div[2]/div/div[5]/div')
action = ActionChains(driver)
action.move_to_element(con_exit)
action.perform()
time.sleep(0.2)
con_exit.click()

The code moves to the download button and clicks it accordingly.
In normal mode - everything works without problems at all, I boot into --headless - nothing happens at all. All prints are there, there are no errors at all, there is no file in the "Downloads" folder either =(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Lyskov, 2019-05-28
@kshnkvn

I assumed that the headless driver does not know which folder to put your download in, and googled something like this https://stackoverflow.com/questions/45631715/downl...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question