我正试图点击本页面中的“输入”按钮:
https://conta.stone.com.br/login
但无论是使用这些类:
"sc-AxhUy hclPzu"
"sc-AxhCb jYjZpM"
也不是XPaths:
"//*[@id="__next"]/div[1]/form/div[1]/div[3]/span/span"
"//*[@id="__next"]/div[1]/form/div[1]/div[3]/span/span/button"
这里的代码目前看起来像这样:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
option = webdriver.ChromeOptions()
browser = webdriver.Chrome(options=option, executable_path=config.CHROME_PATH)
login = "https://conta.stone.com.br/login"
browser.get(login)
username = browser.find_element(by=By.XPATH, value='//*[@id="username"]')
password = browser.find_element(by=By.XPATH, value='//*[@id="password"]')
username.send_keys(email)
password.send_keys(password)
#browser.find_element_by_xpath('//*[@id="recaptcha-anchor"]/div[1]').click()
WebDriverWait(browser, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[starts-with(@src, 'https://www.google.com/recaptcha/api2/anchor')]")))
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='recaptcha-checkbox-border']"))).click()
WebDriverWait(browser, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//*[@id="__next"]/div[1]/form/div[1]/div[3]/span/span/button')))
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="__next"]/div[1]/form/div[1]/div[3]/span/span/button'))).click()
我现在到底做错了什么?我已经尝试了我能想到的大多数方法来找到元素,但没有骰子,如果有人能提出任何建议,那就太好了,一切都很好,直到这个按钮,甚至大部分时间都是recaptcha通过。
我试着用chrome录制这个动作,它给了我以下动作:
{
const targetPage = page;
const element = await waitForSelectors([["aria/Entrar","aria/[role=\"generic\"]"],["#__next > div.clean-page-container__Container-sc-fzay79-0.dGAlqK > form > div.sc-fzoant.MgHsy.card__Card-sc-2xb3kk-0.vMIBG > div.sc-fznLPX.fGbfOF > span > span > button > span"]], targetPage, { timeout, visible: true });
await scrollIntoViewIfNeeded(element, timeout);
await element.click({ offset: { x: 25.15625, y: 12.828125} });
}
我曾尝试在selenium中使用“execute_script”运行它,但由于targetPage没有在Python中定义,所以它没有真正起作用。