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

305
Vistas
How to auto click on <a> tag using selenium (python) which calls a javascript function?

How do I access and click on a button which hyperlinks to a javascript function?

html element:

<a href="javascript:Nav('-index=')" id="ctl04_ctl25_ctl00_lnk2NextPg" class="twPagerBtn right" role="button" onclick="mySpud.container.scrollIntoView();" title="Next Page" aria-label="Next Page">►</a>

My current code:

next_button='//*[@id="ctl04_ctl06_ctl00_lnk2NextPg"]'
try:
    element=WebDriverWait(driver,15).until(
        EC.presence_of_element_located((By.XPATH,next_button))
        
    )

    element.click()
except:
    driver.quit()

Selenium is unable to find the element and I've also tried using the find_element() function using various methods (by id etc) to no avail.

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

0

The locator //*[@id="ctl04_ctl06_ctl00_lnk2NextPg"] doesn't seem to be static.

Try this:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@aria-label='Next Page']"))).click()

If this doesn't work, then you can try this:

element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//a[@aria-label='Next Page']")))
driver.execute_script("arguments[0].click();", element)

Alternate locator:

You can use //*[@title= 'Next Page'] instead of @aria-label locator Alternate locator:

about 4 years ago · Juan Pablo Isaza Denunciar

0

You have to take care of a couple of things here:

  • The initial part of the value of the id attribute is dynamic as in ctl04_ctl25_ctl00_lnk2NextPg and it would change everytime you access the page afresh. So you have to construct a dynamic locator strategy

  • Moving ahead as you are invoking click(), instead of presence_of_element_located() you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[id$='NextPg'][title='Next Page'][aria-label='Next Page']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(@id, 'NextPg')][@title='Next Page' and @aria-label='Next Page']"))).click()
    
about 4 years ago · Juan Pablo Isaza Denunciar

0

Just call the function directly:

driver.execute_script("Nav('-index=')")
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