0
我正在完成註冊和登錄用戶列表的過程。爲什麼我的selenium webdriver身份驗證不起作用(Django 1.9)
我使用相同的用戶名和密碼來簡化事情。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import re
for address in geolocations:
# register
browser.get("http://127.0.0.1:8000/register")
username = browser.find_element_by_id("id_username")
print("username is being set as " + re.sub(' ', '', address))
password = browser.find_element_by_id("id_password")
print("password is being set as " + re.sub(' ', '', address))
location = browser.find_element_by_id("location")
submit = browser.find_element_by_id("register")
username.clear()
password.clear()
location.clear()
username.send_keys(re.sub(' ', '', address))
password.send_keys(re.sub(' ', '', address))
location.send_keys(address)
location.send_keys(Keys.RETURN)
submit.click()
browser.implicitly_wait(1)
# login
browser.get("http://127.0.0.1:8000/login")
username = browser.find_element_by_id("username")
password = browser.find_element_by_id("password")
username.clear()
password.clear()
password.send_keys(re.sub(' ', '', address)) # addresses have spaces
print("password is being set as: " + re.sub(' ', '', address))
browser.implicitly_wait(2)
submit = browser.find_element_by_id("submit")
submit.click()
browser.implicitly_wait(2)
browser.quit()
即使使用相同的字符串進行註冊和登錄,登錄認證也不起作用。但是當我手動註冊/登錄時,相同的用戶名/密碼組合工作。
誰能告訴我是什麼原因造成的?
什麼不起作用?你有錯誤嗎?另外,你一遍又一遍地做're.sub('','',address)'。你應該這樣做一次,保存結果作爲變量,並引用變量。 – elethan