Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

243
Vistas
Python Selenium find element javascript

in page

https://www.virustotal.com/gui/home/upload

a need click "Choose file" but I have Message: javascript error: argument is not defined

var1 = sys.argv[1]
path = os.path.abspath(var1)    

driver.get("https://www.virustotal.com/gui/home/upload")

element = driver.execute_script('return document.querySelector("#view-container > home-view").shadowRoot.querySelector("#uploadForm").shadowRoot.querySelector("#infoIcon").shadowRoot.querySelector("#wrapperLink")')
driver.execute_script('argument[0].click();', element)

How to define this element. I would like to send a file to check using the script

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here is something that works.

element = driver.execute_script('return document.querySelector("#view-container > home-view").shadowRoot.querySelector("#uploadForm").shadowRoot')
file_element = element.find_element(By.CSS_SELECTOR, "#fileSelector")
file_element.send_keys(r"your_file_path/filename.extn")

It submits the file from the backend without clicking on the button and opening the file dialog.

Alternate code:

def open_shadow_root(element):
    shadow_root = driver.execute_script('return arguments[0].shadowRoot', element)
    return shadow_root

driver.get("https://www.virustotal.com/gui/home/upload")
time.sleep(5)
root_1 = driver.find_element(By.CSS_SELECTOR, "#view-container > home-view")
sroot_1 = open_shadow_root(root_1)
print(sroot_1)
time.sleep(4)
root_2 = sroot_1.find_element(By.CSS_SELECTOR, "#uploadForm")
sroot_2 = open_shadow_root(root_2)
time.sleep(4)
file_element = sroot_2.find_element(By.CSS_SELECTOR, "#fileSelector")
file_element.send_keys(r"your_file_path/filename.extn")
time.sleep(4)
driver.quit()

It does the same job as the previous code; it's just that I have written a shadow root function and utilizing it to open the shadow roots. This looks a little more readable in my opinion, but there is no stopping from using the former code. Also, I have used time.sleep() which can be replaced with WebdriverWait if possible.

If you still want to click on the Choose File button and work through the file dialog, then you may try the below:

element = driver.execute_script('return document.querySelector("#view-container > home-view").shadowRoot.querySelector("#uploadForm").shadowRoot')

choose_file = element.find_element(By.CSS_SELECTOR, "#infoIcon")
choose_file.click()

Alternate:

def open_shadow_root(element):
    shadow_root = driver.execute_script('return arguments[0].shadowRoot', element)
    return shadow_root


driver.get("https://www.virustotal.com/gui/home/upload")
time.sleep(4)
root_1 = driver.find_element(By.CSS_SELECTOR, "#view-container > home-view")
sroot_1 = open_shadow_root(root_1)
print(sroot_1)
time.sleep(4)
root_2 = sroot_1.find_element(By.CSS_SELECTOR, "#uploadForm")
sroot_2 = open_shadow_root(root_2)
time.sleep(4)
choose_file = sroot_2.find_element(By.CSS_SELECTOR, "#infoIcon")
choose_file.click()
# ... choose the file ....

driver.quit()
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda