我试图学习2 2Captcha nad作为一个例子,我想建立一个spotify帐户。我已经填好了表格,但唯一关心的是2 2Captcha。我在这里试过各种方法,但都没有用。我试过:
val captcha = driver.findElement(By.id("captcha-div"))
val siteKey = captcha?.getAttribute("data-sitekey") ?: ""
println("Site key: $siteKey")
val solvedCaptcha = getCaptcha(siteKey, "2captchaKey", driver.currentUrl)
val js = driver as JavascriptExecutor
println(solvedCaptcha)
js.executeScript("document.getElementById('g-recaptcha-response').innerHTML='$solvedCaptcha';")
Thread.sleep(500)
val iframe = driver.findElement(By.xpath("//iframe[@title='recaptcha challenge']"))
println(iframe.toString())
driver.switchTo().frame(iframe)
js.executeScript("document.getElementById('recaptcha-verify-button').click();")我使用的网址是这里
更新后的代码(仍然不起作用)添加了模拟击键,希望在检测到任何按键之后可能会触发回调:
val captcha = driver.findElement(By.id("captcha-div"))
val siteKey = captcha?.getAttribute("data-sitekey") ?: ""
println("Site key: $siteKey")
val js = driver as JavascriptExecutor
val findElement = driver.findElement(By.id("g-recaptcha-response"))
js.executeScript("document.getElementById(\"g-recaptcha-response\").style.display = \"inline\";")
val solvedCaptcha = getCaptcha(siteKey, "captchaKey", driver.currentUrl)
println(solvedCaptcha)
solvedCaptcha?.forEach {
findElement.sendKeys(it.toString())
Thread.sleep(Random.nextLong(5L, 30L))
}
Thread.sleep(10000)发布于 2019-11-29 21:09:22
在与click()相关联的复选框中设置重验证码,因为所需的元素位于<iframe>中,因此您必须:
从selenium导入webdriver从options.add_experimental_option('useAutomationExtension',导入WebDriverWait从selenium.webdriver.common.by导入WebDriverWait从selenium.webdriver.support导入expected_conditions as EC options = webdriver.ChromeOptions() options.add_argument(“启动-最大化”)
- Code Block:“启用-自动化”)驱动程序= webdriver.Chrome(options=options,executable_path=r'C:\WebDrivers\chromedriver.exe') driver.get("https://www.spotify.com/gr/signup/") WebDriverWait(驱动程序,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframesrc^='https://www.google.com/recaptcha/api2/anchor'"))) WebDriverWait(驱动程序,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,“span#recaptcha-锚”)).click()

发布于 2019-11-30 03:10:47
这看上去不对:
js.executeScript("document.getElementById('g-recaptcha-response').innerHTML='$solvedCaptcha';")我不知道字符串插补在java中是如何工作的,但我不认为它是这样工作的。
确保设置的值,然后单击绿色按钮,这应该是可行的。
https://stackoverflow.com/questions/59110605
复制相似问题