Open ttraxxrepo opened 1 month ago
Interesting behavior. Did you try to increase sleep times or adding more? Unless we identify the bug, it might be a temporary solution.
@obaskly
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
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()
...
@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?
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
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: