繁体   English   中英

如何与 recaptcha 音频按钮进行交互 selenium python

[英]how to interact with recaptcha audio button selenium python

我正在尝试为百思买产品进行汽车购买。 我一直在寻找使用recaptcha 音频按钮解决recaptcha 的教程。

到目前为止,我已经能够 go 到产品链接。 点击加入购物车。 Go 到购物车。 Go 结帐。 输入 email 和密码,然后单击登录。 现在我需要做一个recaptcha。

From what I read in selenium docs you must first store iframe web element then switch to the selected iframe and then click on the button in the iframe. 但由于某种原因,我无法点击它。 我一直在关注一些示例,例如示例 1示例 2 ,但仍然没有管理它。

这是我到目前为止所拥有的:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

import time

options = webdriver.ChromeOptions() 
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-blink-features=AutomationControlled')
#options.add_experimental_option("excludeSwitches", ["enable-logging"])

driver = webdriver.Chrome(options=options)
driver.maximize_window()

url1 = 'https://www.bestbuy.ca/en-ca/product/amd-ryzen-5-3600-hexa-core-3-6ghz-am4-desktop-processors/15331711'

driver.get(url1)

#addbutton = driver.find_element(By.CSS_SELECTOR, ".addToCartButton")
addbutton = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".addToCartButton")))
        
        
# add to cart
addbutton.click()

print("done adding to cart.. going to signin to checkout now")
        
time.sleep(7)

        
# go to cart
driver.get("https://www.bestbuy.ca/en-ca/basket")

time.sleep(7)

#go to checkout
driver.get("https://www.bestbuy.ca/identity/en-ca/signin?tid=ALeWh7xW3cQ0am2jxPwy%252Bb76uAf3U3S%252FK5kHOt9tXQBdoY3PBPeJZKOnNTI%252BivRSagy1iR3OqazLv%252FDVz33tFdYmNy1NQ5j8XeYNIN%252FeT7HAjsTaVL17znPtcdTyDoY5JsRqidRnIk%252BYGGCG3UKd08fStGLDP3c5gGfENH0sSYglvA%252FdWi1%252BOcpVnGARPpGU2zXiHmeKGfT5NWuMzrOeP57BVjRW6xUfqvAOCRuAio2%252BrBnaNv8hzcIKdEWhZP90QwciiVZTVtl%252BInN8x9bG18AVgIW8AWmfcE8axkpOXJ2GRq1X9PIHlJl122IR8NEpE9nP84GCmMM8kUWCju9Ecsv0RCxmf3o8eByCWoK2HIWiNkMnHCH2EEikSX9xojCG")

print("arrived at signin")
        
#user = driver.find_element_by_id("username")
user = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, "username")))
user.send_keys("thisismyemail@gmail.com")
time.sleep(0.1)

    
time.sleep(1)
        
password = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, "password")))
    
 

password.send_keys("password")
time.sleep(0.15)

print("entered username and password")
    
time.sleep(1.25)



signInBtn = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, "/html/body/div[1]/div/div[3]/div/div/div/div[1]/div/div/form/div/button")))
time.sleep(3)
signInBtn.click()

print("signed in.")

WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[name^='c-xsgh29r4he3'][src^='https://www.google.com/recaptcha/api2/bframe?hl=en-GB&v=bfvuz6tShG5aoZp4K4zPVf5t&k=6LdLhXEUAAAAACZo2QdzqcnoSN7FvEZT8pMykY2s&cb=f835b2sax2o7']")))


print("test")
driver.switch_to_default_content()
audiobutton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "/html/body/div/div/div[3]/div[2]/div[1]/div[1]/div[2]/button")))
time.sleep(3)
audiobutton.click()

print("clicked.")

这一改变使我能够点击验证码音频按钮。

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

import time

options = webdriver.ChromeOptions() 
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-blink-features=AutomationControlled')
#options.add_experimental_option("excludeSwitches", ["enable-logging"])

driver = webdriver.Chrome(options=options)
driver.maximize_window()

url1 = 'https://www.bestbuy.ca/en-ca/product/amd-ryzen-5-3600-hexa-core-3-6ghz-am4-desktop-processors/15331711'

driver.get(url1)

#addbutton = driver.find_element(By.CSS_SELECTOR, ".addToCartButton")
addbutton = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".addToCartButton")))
        
        
# add to cart
addbutton.click()

print("done adding to cart.. going to signin to checkout now")
        
time.sleep(7)

        
# go to cart
driver.get("https://www.bestbuy.ca/en-ca/basket")

time.sleep(7)

#go to checkout
driver.get("https://www.bestbuy.ca/identity/en-ca/signin?tid=ALeWh7xW3cQ0am2jxPwy%252Bb76uAf3U3S%252FK5kHOt9tXQBdoY3PBPeJZKOnNTI%252BivRSagy1iR3OqazLv%252FDVz33tFdYmNy1NQ5j8XeYNIN%252FeT7HAjsTaVL17znPtcdTyDoY5JsRqidRnIk%252BYGGCG3UKd08fStGLDP3c5gGfENH0sSYglvA%252FdWi1%252BOcpVnGARPpGU2zXiHmeKGfT5NWuMzrOeP57BVjRW6xUfqvAOCRuAio2%252BrBnaNv8hzcIKdEWhZP90QwciiVZTVtl%252BInN8x9bG18AVgIW8AWmfcE8axkpOXJ2GRq1X9PIHlJl122IR8NEpE9nP84GCmMM8kUWCju9Ecsv0RCxmf3o8eByCWoK2HIWiNkMnHCH2EEikSX9xojCG")

print("arrived at signin")
        
#user = driver.find_element_by_id("username")
user = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, "username")))
user.send_keys("username@gmail.com")
time.sleep(0.1)

    
time.sleep(1)
        
password = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, "password")))
    
 

password.send_keys("password")
time.sleep(0.15)

print("entered username and password")
    
time.sleep(1.25)



signInBtn = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, "/html/body/div[1]/div/div[3]/div/div/div/div[1]/div/div/form/div/button")))
time.sleep(3)
signInBtn.click()

print("signed in.")

try:    
   # driver.switch_to.frame('c-xsgh29r4he3')
   frame = driver.find_element_by_xpath("//iframe[@title='recaptcha challenge']")
   print("made it!")
   driver.switch_to.frame(frame)
   print("we made it!")

   time.sleep(5)
   

   #audiobutton = driver.find_element_by_xpath("/html/body/div/div/div[3]/div[2]/div[1]/div[1]/div[2]/button")
   audiobutton = driver.find_element_by_id("recaptcha-audio-button")
   audiobutton.click()   


   
   print("complete")
finally:
    test = ""







  
    

暂无
暂无

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

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