Selenium不会等待登录进行身份验证


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

driver = webdriver.Chrome('/usr/local/Caskroom/chromedriver/chromedriver')
wait = WebDriverWait(driver, 20)
driver.implicitly_wait(10) 

driver.get('https://api.engage2learn.org/auth? response_type=token&client_id=esuite&state=cXd5VVlsQkViLWllVkpWLXZFelJfdDFoVTZHT1BkT19WQ3EySGVjQTVsSWNw&redirect_uri=https%3A%2F%2Fesuite.engage2learn.org%2Findex.html&scope=') 
email = driver.find_element(By. ID, 'loginform-username')
email.send_keys('email to log in')
password = driver.find_element(By.ID, 'loginform-password')
password.send_keys('password to log in')
driver.find_element(By.CSS_SELECTOR , 'button').click()
wait

一切正常,直到登录过程开始,然后页面重置为原始登录页面,清除所有字段。登录过程是手动进行的,网站上没有机器人。但是,一旦自动化开始,站点开始验证登录凭据,它就会重置到原始登录页面,并清除所有字段。

在不了解网站和登录详细信息的情况下,很难给出合适的解决方案,但一个简单的解决方案是将chromedriver配置为使用已经登录到网站的Chrome配置文件:

# Uses main chrome profile
options = webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=/path/to/your/chrome/profile')
s = Service('chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
driver.get(url);

相关内容

  • 没有找到相关文章