How to verify a random number generation and provide a calculation

684 views Asked by At

I have a Website https://www.ultimateqa.com/complicated-page/ on the website there is a form to fill in that has a Captcha which produces random numbers and asked the user to do the addition and enter a number.

I am trying to do this on Selenium using Java.

How can I verify the random numbers, take themr, do the calculation and then add the answer to the input field?

1

There are 1 answers

1
Dmitri T On BEST ANSWER
  1. Locate web element holding the captcha challenge

    WebElement element = driver.findElement(By.className("et_pb_contact_captcha_question"));
    
  2. Get its text into a String:

    String captchaText = element.getText();
    
  3. Evaluate the string value using i.e. ScriptEngine

    String captchaResult = new javax.script.ScriptEngineManager().getEngineByName("javascript").eval(captchaText).toString();
    
  4. That should be it:

    enter image description here

In more complex captcha challenges where you cannot find the values in the page source you will have to go for an OCR or image recognition library like OpenCV or Tesseract or SeeTest