Python Forum
Issue closing an Modal Alert (popup)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue closing an Modal Alert (popup)
#9

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 valid
Here 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)
Reply


Messages In This Thread
RE: Issue closing an Modal Alert (popup) - by leviathan54 - Apr-23-2019, 02:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to use data from an API, to create an alert? PopFendi 8 3,850 Apr-22-2021, 02:21 PM
Last Post: PopFendi
  Monitor specific line of code and get alert Olimpiarob 0 1,540 Jul-08-2020, 10:06 AM
Last Post: Olimpiarob
  Python / Selenium Turning Off Alert graham23s 3 8,306 Aug-18-2019, 02:12 PM
Last Post: metulburr
  Selenium click on popup button??? GuJu 7 7,975 Jul-20-2019, 09:21 AM
Last Post: Nizam
  Getting error when accessing elements in a modal window of an webpage using selenium sumandas89 3 8,714 Jul-13-2018, 10:44 AM
Last Post: mlieqo
  How to access Modal window using Selenium Python sumandas89 0 4,238 Mar-30-2018, 08:21 AM
Last Post: sumandas89
  Generic If Popup Exists Close It Script digitalmatic7 1 2,505 Feb-18-2018, 07:24 AM
Last Post: metulburr
  popup login form in django uditvashisht 0 3,832 Jan-31-2018, 11:55 PM
Last Post: uditvashisht
  selenium bypass javascript popup box metulburr 6 8,468 Jun-02-2017, 07:15 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020