Search code examples
excelvbaselenium-webdriverselenium-chromedriverrecaptcha

Issue about make a new challenge on Google reCAPTCHA via Selenium in VBA EXCEL?


Follow the picture, I need to click on the new challenge via Selenium in Excel VBA.

enter image description here

Bellow is my code in VBA Excel:

Option Explicit
Public driver As Selenium.ChromeDriver
Public Sub reCAPTCHAClicker()
    Set driver = New Selenium.ChromeDriver
    driver.Start
    driver.Window.Maximize
    driver.Get " " 'The website I am trying to work on it.
    driver.SwitchToFrame (0) 'To go inside the iframe of the reCAPTCHA.
    driver.FindElementByClass("recaptcha-checkbox-border").Click 'Click on the checkbox of reCAPTCHA.
    driver.wait (3000) 'Wait until picture selecting appears.
    DoEvents
    driver.SwitchToFrame (0) 'To go inside the iframe of the picture selecting.
    DoEvents
    driver.wait (3000) 'Wait because the system does not recognize me as robot.
    driver.FindElementById("recaptcha-reload-button").Click

So as you see I tried by ID at the last line. but it says:

enter image description here

Then I changed the last line by its class:

driver.FindElementByClass("rc-button goog-inline-block rc-button-reload").Click

but it says:

enter image description here

After that I tried by its upper class. So I changed last line to this:

driver.FindElementByClass("button-holder reload-button-holder").Click

but it says again:

enter image description here

So I got confused!!! Could you please help me on this? 😫😫😫

Also please see this picture, which is the inspect of the new challenge button:

enter image description here


Solution

  • I found this solution:

    Option Explicit
    Public driver As Selenium.ChromeDriver
    Public Sub reCAPTCHAClicker()
        Set driver = New Selenium.ChromeDriver
        driver.Start
        driver.Window.Maximize
        driver.Get " " 'The website I am trying to work on it.
        driver.SwitchToFrame (0) 'To go inside the iframe of the reCAPTCHA.
        driver.FindElementByClass("recaptcha-checkbox-border").Click 'Click on the checkbox of reCAPTCHA.
        driver.wait (3000) 'Wait until picture selecting appears.
        DoEvents
        driver.SwitchToDefaultContent 'To get back outside from iframe(0)
        driver.SwitchToFrame (2) 'To go inside the iframe of the picture selecting.
        DoEvents
        driver.wait (3000) 'Wait because the system does not recognize me as robot.
        driver.FindElementById("recaptcha-reload-button").Click
        driver.SwitchToDefaultContent 'To get back outside from iframe(2)
    End Sub