在 selenium 上禁用按钮时遇到问题

having trouble with disabled button on selenium

我正在尝试使用 selenium 登录一个站点,在这个站点中,'enter' 字段被禁用,只有在您开始输入后才会启用。问题是,当我使用 sendkeys 输入用户名时,按钮不会将 'enable status' 更改为 true。我能做什么?

t1 = time.perf_counter()
url = 'https://auth.iupp.com.br/login?client_id=2raqh4sjj73q10efeguphmk4gn&nonce=5149eba248ed491cbde001d686e688dd&redirect_uri=https%3A%2F%2Fwww.iupp.com.br%2Fauth%2Fcallback&response_type=token&scope=profile%20email%20openid%20aws.cognito.signin.user.admin%20webpremios.campaigns%2F40455&state=dc6544eec0244aa0be61d3b8aeded338'

op = webdriver.ChromeOptions()
op.add_argument('headless')
op.add_argument("user-agent=" + ua.random)
op.add_argument("incognito")
driver = webdriver.Chrome(options=op)

driver.get(url)
driver.implicitly_wait(5)
username = driver.find_element_by_xpath(".//*[@id='username']")
username.send_keys("45143080581")

print('0')
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "btnContinue")))
print('1')
driver.find_element_by_id("btnContinue").click()

bs = BeautifulSoup(driver.page_source, 'html.parser')  
driver.quit() 

t2 = time.perf_counter()
print(f'tempo:{t2-t1}')

Ps:输出显示 0 和 1 打印

wait = WebDriverWait(driver, 30)
t1 = time.perf_counter()
driver.get('https://auth.iupp.com.br/login?client_id=2raqh4sjj73q10efeguphmk4gn&nonce=5149eba248ed491cbde001d686e688dd&redirect_uri=https%3A%2F%2Fwww.iupp.com.br%2Fauth%2Fcallback&response_type=token&scope=profile%20email%20openid%20aws.cognito.signin.user.admin%20webpremios.campaigns%2F40455&state=dc6544eec0244aa0be61d3b8aeded338')

wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,'#root > div > div.alertLDGPBackground > div > div > div > div.col-12.col-md-auto.txt-center > a'))).click()
print('0')         
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,'#username'))).send_keys('45143080581')
print('1')

wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,'#btnContinue'))).click()

bs = BeautifulSoup(driver.page_source, 'html.parser')  
driver.quit() 

t2 = time.perf_counter()
print(f'tempo:{t2-t1}')
  1. 您应该在页面加载时单击“接受”以确保其他元素可单击。
  2. 只需使用等待等待元素可点击即可。

导入:

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