Apr-23-2019, 02:00 PM
(This post was last modified: Apr-23-2019, 02:00 PM by leviathan54.)
Following suggestion from @Larz60+ I have simplified the code so username/password is hardcoded and no spreadsheet is referenced.
It looks to me like the accept alert is actually working with this script BUT something is happening that preventing me recording the test result. so for example if i successfully login then it will print "test is passed" but if i don't successfully login it does not print "test failed". Instead I get this error message
Traceback (most recent call last): File "C:/Users/David/PycharmProjects/POM/Login2.py", line 21, in <module> if driver.title == "Guru99 Bank Manager HomePage": File "C:\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 342, in title resp = self.execute(Command.GET_TITLE) File "C:\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 241, in check_response raise exception_class(message, screen, stacktrace, alert_text) selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: None Message: Dismissed user prompt dialog: User or Password is not validHere is my simplified script. You can cut and paste this script to test with
from selenium import webdriver import unittest from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC profile_path = 'C:/FireFoxProfile' profile = webdriver.FirefoxProfile(profile_path) driver = webdriver.Firefox(firefox_profile=profile_path) driver.implicitly_wait(2) driver.get('http://www.demo.guru99.com/V4/') driver.maximize_window() username = "mngr189426" #correct password is "mngr189426" password = "fail" #correct password is "hapEnyn" driver.find_element_by_name("uid").send_keys(username) driver.find_element_by_name("password").send_keys(password) driver.find_element_by_name("btnLogin").click() #if login is successful then check website is on right page and pass/fail test if driver.title == "Guru99 Bank Manager HomePage": print("test is passed") else: print("test failed") # return to homepage and insert password/username for next row in spreadsheet WebDriverWait(driver, 20).until(EC.alert_is_present).accept if __name__ == '__main__': unittest.main(verbosity=2)