[Python] How to upload a file using Selenium when HTML element is hidden?

Discussão em 'Python' iniciado por Stack, Outubro 2, 2024.

  1. Stack

    Stack Membro Participativo

    I am working in a project using Selenium with Python. I need to upload a file, but different from other places, the filetype input is not available. I thought it was only hidden, but it seems that the input only appears after clicing in the upload button. I guess there is a script or something that makes it appears, but I don't know how to solve it.

    I uploaded a picture that shows the class that changes:

    Before Clicking: --> div class="input-group"--input type="text" class="form-control" readonly="" placeholder="Arraste um arquivo aqui ou clique no botão para pesquisar" value="" style=""--div class="input-group-btn"></span--/button><ul class="dropdown-menu pull-right"--/ul--/div--/div>

    After Clicking: --> div class="input-group"--input type="text" class="form-control" readonly="" placeholder="Arraste um arquivo aqui ou clique no botão para pesquisar" value="" style=""--div class="input-group-btn"><span class="fa fa-upload"--/span></button--ul class="dropdown-menu pull-right"--/ul--/div><input type="file" class="input_arquivo hidden"--/div>

    My code is like this today: File_Upload = path Anexo1 = navegador.find_element(By.XPATH,'.//input[@placeholder="Arraste um arquivo aqui ou clique no botão para pesquisar"]') Anexo1.click() Anexo1 = navegador.find_element(By.XPATH,'/html/body/div[2]/div/div[2]/div[3]/div1/div/div1/div[2]/div[3]/div[2]/div[2]/div1/div/div1/div[2]/div[3]/div[2]/div/div1/div/div1/div[3]/div[2]/div[2]/div/div/div[2]/table/tr1/td[7]/div/div/div/input[2]') Anexo1.send_keys(File_Upload)

    It works, but the program shows the upload screen and I donwt know how to close it. Anybody knows how to close it or make it without clicking the button? Thanks a lot!!!

    HTML CHANGING

    Continue reading...

Compartilhe esta Página