简体   繁体   English

Selenium 提交按钮元素不可交互

[英]Selenium submit button element not interactable

I posted recently about some trouble I was having with selenium, primarily the anticaptcha API.我最近发布了关于 selenium 遇到的一些问题,主要是反验证码 API。 Ive managed to solve that but I am having some trouble over here.我设法解决了这个问题,但我在这里遇到了一些麻烦。 This is my current code:这是我当前的代码:

from time import sleep
from selenium import webdriver
from python_anticaptcha import AnticaptchaClient, NoCaptchaTaskProxylessTask
import os
import time

#Gather Api Key
api_key = 'INSERT API KEY HERE'

#Go to the acc registration site
browser = webdriver.Chrome()
browser.implicitly_wait(5)
browser.get('https://www.reddit.com/register/')
sleep(2)

#Input email
email_input = browser.find_element_by_css_selector("input[name='email']")
email_input.send_keys("INSERT EMAIL HERE")

#Continue to the next part of the registration process
continue_button = browser.find_element_by_xpath("//button[@type='submit']")
continue_button.click()

#Find and input the username and password fields
username_input = browser.find_element_by_css_selector("input[name='username']")
password_input = browser.find_element_by_css_selector("input[name='password']")

username_input.send_keys("INSERT USERNAME HERE")
password_input.send_keys("INSERT PASSWORD HERE")


#Gather site key
url = browser.current_url
site_key = "6LeTnxkTAAAAAN9QEuDZRpn90WwKk_R1TRW_g-JC"

#Acc do the solving process
client = AnticaptchaClient(api_key)
task = NoCaptchaTaskProxylessTask(url, site_key)
job = client.createTask(task)
print("Waiting for recaptcha solution")
job.join()

# Receive response
response = job.get_solution_response()
print(response)
print("Solution has been gotted")

# Inject response in webpage
browser.execute_script('document.getElementById("g-recaptcha-response").innerHTML = "%s"' % (response))
print("Injecting Solution")

# Wait a moment to execute the script (just in case).
time.sleep(1)
print("Solution has been gotted for sure")

# Press submit button
browser.implicitly_wait(10)
Signup = browser.find_element_by_xpath('//input[@type="submit"]')
Signup.click()

Everything runs smoothly except for the final line.除了最后一行,一切都很顺利。 I think the program is recognizing the submit button but for some reason gives an element not interactable error.我认为程序正在识别提交按钮,但由于某种原因给出了一个元素不可交互的错误。 Any help on how to solve this would be greatly appreciated任何有关如何解决此问题的帮助将不胜感激

I had the same issue when I was using selenium.我在使用 selenium 时遇到了同样的问题。 Sometimes it happens that even though selenium has recognized the element, its function is not "ready."有时会发生即使 selenium 已识别该元素,其 function 还没有“准备好”。 Adding a delay before clicking the submit button should fix the issue.在单击提交按钮之前添加延迟应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM