A
A
Alan Gibizov2021-10-11 14:15:26
JavaScript
Alan Gibizov, 2021-10-11 14:15:26

How to download file by selenium by clicking on input submit button with js script?

I'm trying to download a file by selenium clicking on a bootstrap input button.
The button looks like this:

<input type="submit" value="Экспорт" onclick="hideModal(this);">

The button is in the modal, but it seems like there is some access to it - I click on it with a script (it is not clicked directly through selenium):
driver.execute_script('document.querySelector("#csv-export-form > p.buttons > input[type=submit]").click()')

At the same time, the corresponding line appears in chrome in DevTools / Network - but for a while it thinks and turns red, the download does not occur.
If we take the same JS code
document.querySelector("#csv-export-form > p.buttons > input[type=submit]").click()'

and run in DevTools/Console under the same conditions (i.e. the page state is the same as before, in the same Chrome called by selenium), then the same line appears in DevTools/Network, and the download is normal, as if I clicked the mouse.
spoiler
61641ac3f2fef388776565.png


What is missing so that the download starts from selenium? And where to look to find out?

ps selenium v.3.141.0, under Python.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alan Gibizov, 2021-11-13
@phaggi

Found! Turns out I was using the wrong webdriver method! You should have used .submit() instead of .click() . And everything worked.

N
Nadim Zakirov, 2021-10-11
@zkrvndm

https://qna.habr.com/q/885545

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question