Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting stuck before clicking 'audio button' #9

Open
ttraxxrepo opened this issue Aug 8, 2024 · 5 comments
Open

Getting stuck before clicking 'audio button' #9

ttraxxrepo opened this issue Aug 8, 2024 · 5 comments

Comments

@ttraxxrepo
Copy link

Having some odd behavior, it seems like sometimes it works and sometimes it doesn't... I am running the selenium RecaptchaSolvery.py

When it doesn't work, it gets to this point and then seems to not be able to click/find the audio button:

Screenshot 2024-08-07 at 7 50 50 PM
@sarperavci
Copy link
Owner

Interesting behavior. Did you try to increase sleep times or adding more? Unless we identify the bug, it might be a temporary solution.

@obaskly

@ttraxxrepo
Copy link
Author

ttraxxrepo commented Aug 8, 2024

I did, at first adding time.sleep(2) to line 59 seems to have worked... until it didn't...

Playing around some more and think I have identified the issue, it seems the website is stacking recaptchas. there are 3 iframes with title = recaptcha challenge expires in two minutes ... so playing around with some javascript to see if I can always get the one on top identified and then switch to that one as opposed to just relying on the title, since iframe title is not unique to html element

@ttraxxrepo
Copy link
Author

ttraxxrepo commented Aug 8, 2024

Think I got it - may be better to use this as the default instead, this way if there is only 1 iframe with the title it will find it, but if there are multiple it'll always get the one on top

    def solveAudioCaptcha(self):
        try:
            self.driver.switch_to.default_content()
            # Execute JavaScript to get the topmost iframe with a specific title
            top_frame = self.driver.execute_script(
                """
                var iframes = document.getElementsByTagName('iframe');
                var topFrame = null;
                var highestZIndex = -1;
                for (var i = 0; i < iframes.length; i++) {
                    var iframe = iframes[i];
                    if (iframe.title === 'recaptcha challenge expires in two minutes') {
                        var zIndex = window.getComputedStyle(iframe).zIndex;
                        var zIndexNumber = (zIndex === 'auto') ? -1 : parseInt(zIndex, 10);
                        
                        if (zIndexNumber >= highestZIndex) {
                            highestZIndex = zIndexNumber;
                            topFrame = iframe;
                        }
                    }
                }
                return topFrame ? {src: topFrame.src, title: topFrame.title} : null;
            """
            )
            # Switch to the audio CAPTCHA iframe
            iframe_audio = WebDriverWait(self.driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, f"//iframe[@src='{top_frame['src']}']")))
            # Click on the audio button
            audio_button = WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.ID, "recaptcha-audio-button")))
            audio_button.click()

            ...

@obaskly
Copy link

obaskly commented Aug 8, 2024

@ttraxxrepo This is interesting. I've never encountered this case before while solving captchas.
We can set it as default, but is it always that only the captcha on top is the one that needs to be solved?

can you provide the website link?

@ttraxxrepo
Copy link
Author

It appears so. A human would only ever be able to "click" whatever the topmost captcha is, so it's a way of a bot not knowing (potentially) which element to grab.

timewall ( dot ) io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants