Soo 基本上我試圖制作一個 python 程式來從一個不和諧的機器人那里獲得我的日常獎勵,但我無法點擊“Pegar Premio”按鈕。
我的代碼:(我是 python 新手)
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
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
options.add_argument(r"--user-data-dir=PathToMyProfile")
driver = webdriver.Chrome(options=options)
driver.get("https://loritta.website/br/daily")
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name^='a-'][src^='https://www.google.com/recaptcha/api2/anchor?']")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[@id='recaptcha-anchor']"))).click()
driver.find_element(By.XPATH, '//*[@id="daily-wrapper"]/div[3]/div').click()
driver.quit()
uj5u.com熱心網友回復:
@Andersonbap,似乎您要單擊“Pegar Premio”按鈕的元素不在 iframe 內,所以我洗掉了該行。我還更改了按鈕的選擇器。以下對我有用。添加了 time.sleep() 以便您可以查看頁面上發生的事情,一旦事情正常,您可以將其洗掉:
driver.get("https://loritta.website/br/daily")
time.sleep(5)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "button-discord"))).click()
driver.find_element(By.XPATH, '//*[@id="daily-wrapper"]/div[3]/div').click()
time.sleep(5)
driver.quit()
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/515820.html
下一篇:Xcode14按鈕網格
