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

106
Vistas
VB.Net - Selenium can't find a javascript function on the page I want to run

I am trying to make some automation software automating Chrome. I can navigate to the page, and the page has a button declared like this in the code:

<div class="bn_diff_image">
   <a href="javascript:setMode('ImageText', 0);"></a>
</div>

The class shows an image of a button. I need to click that button (to execute the javascript) but I can't get it to work. Here is the code I have tried:

chromeDriver.ExecuteJavaScript("javascript:setMode('ImageText', 0)")

This returns an error that setMode cannot be found. I put a Thread.Sleep in the code to ensure the page was fully loaded before calling this, it made no difference

I tried accessing the button via CSS selector

chromeDriver.FindElement(By.CssSelector("a[href*=\'ImageText', 0']")).Click()

It can't find the selector and fails

I tried finding the div by classname and clicking on that

chromeDriver.FindElement(By.ClassName("bn_diff_image")).Click()
    '

but it fails saying it can't find the element

How in the world can I click on this link or run that javacript on the page?

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

0

Please try this css selector :

div.bn_diff_image a[href^='javascript:setMode']

use it like this :

chromeDriver.FindElement(By.CssSelector("div.bn_diff_image a[href^='javascript:setMode']")).Click()
about 4 years ago · Juan Pablo Isaza Denunciar

0

Never Mind, I am bad at this, The element was in an iFrame. Once I elected the Frame it worked

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