Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!