我正在尝试运行以下代码来登录Web应用程序,但它无法运行。我得到的结果是“FAILED(errors = 1)”。有人可以解释这里的问题吗?它应该是一个简单的登录,但我没有在用户名或密码中看到Web驱动程序类型。
class LoginTest(unittest.TestCase):
username = "example"
password = "example"
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.get("http://www.crowdfireapp.com")
def test_Login(self):
signInButtonSelector = ".btn-primary-outline"
signInTwitterButtonSelector = "#signinModal > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > a:nth-child(3)"
emailFieldSelector = "div.row:nth-child(2) > label:nth-child(1)"
passFieldSelector = "#password"
emailFieldElement = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_css_selector(emailFieldSelector))
passFieldElement = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_css_selector(passFieldSelector))
emailFieldElement.send_keys(username)
passFieldElement.send_keys(password)
passFieldElement.send_keys(Keys.RETURN)
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()
答案 0 :(得分:0)
您可以使用https://accounts.crowdfireapp.com/auth/twitter?rememberMe=true&firebotVersion=2.1
而不是http://www.crowdfireapp.com
获取Twitter登录页面。
然后您的代码将在下面使用:
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.get("https://accounts.crowdfireapp.com/auth/twitter?rememberMe=true&firebotVersion=2.1")
def test_Login(self):
signInButtonSelector = ".btn-primary-outline"
signInTwitterButtonSelector = "#signinModal > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > a:nth-child(3)"
emailFieldSelector = "#username_or_email"
passFieldSelector = "#password"
emailFieldElement = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_css_selector(emailFieldSelector))
passFieldElement = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_css_selector(passFieldSelector))
emailFieldElement.send_keys(username)
passFieldElement.send_keys(password)
passFieldElement.send_keys(Keys.RETURN)