Home > Mobile >  Can't click a button into loritta's website with selenium
Can't click a button into loritta's website with selenium

Time:10-13

Soo basically i was trying to make a python program to get my daily rewards from a discord bot, but i can't manage to click into the button " Pegar Premio".

My code: (I'm new to 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()

CodePudding user response:

@Andersonbap, seems the element you want to click "Pegar Premio" button is not inside the iframe so I removed that line. Also I changed the selector for the button. The following is working for me. time.sleep() are added so you can see what is happening on the page which you can remove once things are working:

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()
  • Related