0

I'm trying to signup on twitter using selenium and using 2captcha API to solve the captcha but for some reason when clicking continue the page refreshes and doesn't proceed

        captchaInput = twitter_driver.find_element_by_id('g-recaptcha-response')
        print("Text area set to visible")
        twitter_driver.execute_script("arguments[0].setAttribute('style','display:visible;');", captchaInput)
        time.sleep(5)
        print("Entering captcha token")
        captchaInput.send_keys(captcha_token)
        time.sleep(5)
        button_click = "javascript:document.getElementById('continue_button').click();"
        twitter_driver.execute_script(button_click)
Arfath Yahiya
  • 107
  • 12

2 Answers2

0

if you write on Python try to do so

wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#your selector'))).click()

there very good all written https://selenium-python.readthedocs.io/locating-elements.html#:~:text=content%20%3D%20driver.find_element_by_css_selector(%27p.content%27)

if at your don`t try describe the error in more detail

Vadim
  • 1
  • 1
  • The element was hidden so i used JS to click on it and again on another hand I also tried ```button = twitter_driver.find_element_by_xpath("//input[@id='continue_button']") twitter_driver.execute_script("arguments[0].setAttribute('style','display:visible;')", button)``` and then click on it – Arfath Yahiya Sep 20 '21 at 14:37
  • use always css selector – Vadim Sep 20 '21 at 14:42
  • I can't access this element using css selector as it's display is none and it raises the `NoSuchElementException` – Arfath Yahiya Sep 20 '21 at 14:47
  • that's right it won't do anything because it's hidden – Vadim Sep 20 '21 at 14:56
  • it get's visible once I solve the captcha manually, I think this is one of the [callback captcha](https://2captcha.com/2captcha-api#callback) if it is then i need to find the callback function – Arfath Yahiya Sep 20 '21 at 15:05
  • then you need to first make a condition for the element to become visible, then click it – Vadim Sep 20 '21 at 15:15
  • I know but the captcha thing needs to be solved via script so i can click on the continue button – Arfath Yahiya Sep 20 '21 at 15:18
0

So answering my own question just for records, twitter uses callback captcha so unsolved captcha reloads the page even if you click on the submit button via JS

This gist helped me solving the captcha issue

Arfath Yahiya
  • 107
  • 12