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)
#1
Hi All

I'm playing around with the following site (python 37/Selenium).

http://www.demo.guru99.com/V4/index.php

When i type in an incorrect password or username. I get a popup/alert.

I cant understand how to find element of the popup so i can select "ok" in the popup. I know about the find_element commands but when i open the inspector i cant see the elements of the popup.

If I understand the documentation correctly the following line would work
driver.switch_to_alert().accept without pointing it any particular element but
when i plug it into pycharm the following seems to happen driver.[strike]switch_to_alert[/strike]().alert() (i.e. strikethough in the switch_to_alert).

I played around with the line driver = driver.switch_to_alert(). It looks like it has strike though when i place it below the following line self.driver() but has no strikethough if i place it above the following line line self.driver() in line 3 (all in the same def function.)

In the code snippet below - i enter the username/password. If it is correct (ie line 18 it is passed) but if incorrect username or password (ie the else condition in line 21) i need to be able to press ok on the alert that popsup.

Can someone explain how i get around this?

   def test_login_valid(self):
        
        driver = self.driver
        driver.get('http://www.demo.guru99.com/V4/')
        path = "C://FireFoxProfile/login1.xlsx"

        rows = spreadsheet.getRowCount(path, 'Sheet1')

        login = LoginPage(driver)
#loop to extract username and password from spreadsheet and enter into website demo.guru
        for r in range(2, rows + 1):
            username = spreadsheet.readData(path, "Sheet1", r, 1)
            password = spreadsheet.readData(path, "Sheet1", r, 2)
            login.enter_username(username)
            login.enter_password(password)
            login.click_login()
#if username and Passwork then check page is loaded, else fail page
            if driver.title == "Guru99 Bank Manager HomePage":
                print("test is passed")
                spreadsheet.writeData(path, "Sheet1", r, 3, "test passed")
            else:
                print("test failed")
                spreadsheet.writeData(path, "Sheet1", r, 3, "test failed")
            # return to homepage and insert password/username for next row in spreadsheet
            driver.switch_to_alert().accept  #whats the issue with this line? I need to click OK on the # alert/popup
            
            
        time.sleep(2)
I would be so grateful if someone can point me in right direction.
Reply


Messages In This Thread
Issue closing an Modal Alert (popup) - by leviathan54 - Apr-21-2019, 07:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to use data from an API, to create an alert? PopFendi 8 3,963 Apr-22-2021, 02:21 PM
Last Post: PopFendi
  Monitor specific line of code and get alert Olimpiarob 0 1,577 Jul-08-2020, 10:06 AM
Last Post: Olimpiarob
  Python / Selenium Turning Off Alert graham23s 3 8,390 Aug-18-2019, 02:12 PM
Last Post: metulburr
  Selenium click on popup button??? GuJu 7 8,163 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,789 Jul-13-2018, 10:44 AM
Last Post: mlieqo
  How to access Modal window using Selenium Python sumandas89 0 4,302 Mar-30-2018, 08:21 AM
Last Post: sumandas89
  Generic If Popup Exists Close It Script digitalmatic7 1 2,534 Feb-18-2018, 07:24 AM
Last Post: metulburr
  popup login form in django uditvashisht 0 3,856 Jan-31-2018, 11:55 PM
Last Post: uditvashisht
  selenium bypass javascript popup box metulburr 6 8,544 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