Now let me tell you a few things
- way1 is so basic but not dinamic;
you can do it with a python module; this module name is pyautogui
import pyautogui
pyautogui.click(x=X coordinate of the button you want to press, y=#Y coordinate of the button you want to press)
you can ask how can know cordinates of button, you can use pyautogui.position()
and after find cordinates use them on above
NOTE: don't forget that when in the background you can't click your button(here is the why not dinamic)
I don't think this(shadow-root) is the reason why you can't press the button. As for my guess;
as far as i know the button you are looking for is inside the iframe so you can't click until you get inside the iframe. Since I don't know the id of the button you are looking for and I don't have much time for now, let me show you how the audio button is pressed (the logic is probably the same as the button you are looking for) . All you have to do is to write the correct id.
class Captcha:
def __init__(self):
self.option = webdriver.ChromeOptions()
self.option.add_argument('--disable-notifications')
self.option.add_argument('--mute-audio')
self.option.add_argument("user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1")
self.driver = webdriver.Chrome(options = self.option)
def start_to_bypasscaptcha(self):
self.driver.get(#URL of site)
time.sleep(5)
googleClass = self.driver.find_elements_by_class_name('g-recaptcha')[0]
outeriframe = googleClass.find_element_by_tag_name('iframe')
outeriframe.click()
allIframesLen = self.driver.find_elements_by_tag_name('iframe')
audioBtnFound = None
audioBtnIndex = -1
for index in range(len(allIframesLen)):
self.driver.switch_to.default_content()
iframe = self.driver.find_elements_by_tag_name('iframe')[index]
self.driver.switch_to.frame(iframe)
try:
print(self.driver.find_element_by_id("audio-instructions").text)
time.sleep(1)
audioBtn = self.driver.find_element_by_id('recaptcha-audio-button') or self.driver.find_element_by_id('recaptcha-anchor')
audioBtn.click()
audioBtnFound = True
audioBtnIndex = index
break
except Exception as error:
pass
time.sleep(3)
if audioBtnFound:
#do what do you want
else:
print('Button not found.')
If you apply this code to the button you want properly and it doesn't work, you are right, shadow-root may be the cause of this problem.
description of my code;
- open chrome using selenium
- go to the URL
- wait a few second after that find captcha
- Find all iframes inside captcha frame
- every time go inside the found iframes and try to click the button
- when you find the clickable button end the loop and assign a variable which iframe the button belongs to
Very serius note; I would like to point out that the second way was not written for the purpose of giving an answer, the main purpose is to show the logic.