Home > OS >  having trouble with disabled button on selenium
having trouble with disabled button on selenium

Time:06-02

Im trying to login in a site with selenium, in this site, the 'enter' field is disabled, and it will only be enabled after you starting typing. The problem is that when I enter the username with sendkeys the button won't change the 'enable status' to true. What can I do?

t1 = time.perf_counter()
url = 'https://auth.iupp.com.br/login?client_id=2raqh4sjj73q10efeguphmk4gn&nonce=5149eba248ed491cbde001d686e688dd&redirect_uri=https://www.iupp.com.br/auth/callback&response_type=token&scope=profile email openid aws.cognito.signin.user.admin webpremios.campaigns/40455&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: the output show 0 and 1 printed

CodePudding user response:

wait = WebDriverWait(driver, 30)
t1 = time.perf_counter()
driver.get('https://auth.iupp.com.br/login?client_id=2raqh4sjj73q10efeguphmk4gn&nonce=5149eba248ed491cbde001d686e688dd&redirect_uri=https://www.iupp.com.br/auth/callback&response_type=token&scope=profile email openid aws.cognito.signin.user.admin webpremios.campaigns/40455&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. You should click the accept when the page loads to make sure the other element is clickable.
  2. Just wait for the element to be clickable using waits.

Import:

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