Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何执行js脚本并从selenium发送var_Python_Selenium_Selenium Webdriver - Fatal编程技术网

Python 如何执行js脚本并从selenium发送var

Python 如何执行js脚本并从selenium发送var,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,我试图用API解决一个不可见的reCaptcha,但我不知道如何执行回调函数并用selenium发送令牌 下面是我的代码片段 from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by i

我试图用API解决一个不可见的reCaptcha,但我不知道如何执行回调函数并用selenium发送令牌

下面是我的代码片段

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
from anticaptchaofficial.recaptchav2proxyless import *


def solve_recaptcha(site):
    

    solver = recaptchaV2Proxyless()
    solver.set_verbose(1)
    solver.set_key("mykey")
    solver.set_website_url(site)
    solver.set_website_key("6LcmDCcUAAAAAL5QmnMvDFnfPTP4iCUYRk2MwC0-")
    
    
    g_response = solver.solve_and_return_solution()
    if g_response != 0:
        return g_response
    else:
        return 0


site = 'https://recaptcha-demo.appspot.com/recaptcha-v2-invisible.php'
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options,executable_path='chromedriver.exe')    
driver.get(site)

g_recaptcha = solve_recaptcha(site)
driver.execute_async_script("var token = '{}'; onSubmit(token);", g_recaptcha)
WebDriverWait(driver, 2).until(EC.visibility_of_element_located((By.XPATH, "//button[contains(text(), 'Submit ↦')]"))).click()
这就是功能:

提交函数(令牌){
document.getElementById(“演示表单”).submit();
}

该函数对令牌没有任何作用。您需要找到textarea并将其设置为innerText,然后提交表单。我已尝试使用以下命令在
g-recaptcha-response
中发送令牌:
driver.execute_script(““”document.getElementById(“g-recaptcha-response”).innerHTML=arguments[0]”,g_recaptcha)
,然后单击submit。但它也不起作用。嗯,实际上我觉得这很合适。确保验证码是正确的,并且没有回调。实际上有回调。如果代码已更改,则应该更新您的问题。该函数对令牌没有任何作用。您需要找到textarea并将其设置为innerText,然后提交表单。我已尝试使用以下命令在
g-recaptcha-response
中发送令牌:
driver.execute_script(““”document.getElementById(“g-recaptcha-response”).innerHTML=arguments[0]”,g_recaptcha)
,然后单击submit。但它也不起作用。嗯,实际上我觉得这很合适。确保验证码是正确的,没有回调。实际上有回调。如果代码发生了变化,你应该更新你的问题