0

What I want is to continue with the next iteration if there is a pop up message in the webpage being scrapped. That is if there is any pop up message, I want to accept that message and go to the next item i.e go to the beginning of the loop.

For this I use the following snippet of code:

from tkinter import *
from tkinter import messagebox as msg
from tkinter import filedialog as fd
from tkinter import ttk
from tkinter import StringVar as sv
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException


for(i in range(0,5)):
      try:
          click_alert=driver.switch_to_alert()
          click_alert.accept()

          continue
      except TimeoutException:
           print('wrong value in'+i+'th row . Please check the value ') 

The following error shows up:

Exception in Tkinter callback

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 1699, in __call__
    return self.func(*args)
  File "C:/Users/chowdhuryr/Desktop/ATT RESEARCH BOT/GUI.py", line 64, in printMessage
    self.Scrapper(str1,str2)
  File "C:/Users/chowdhuryr/Desktop/ATT RESEARCH BOT/GUI.py", line 163, in Scrapper
    click_alert=driver.switchTo().alert()

Now I am pretty certain that the error lies in click_alert=driver.switch_to_alert() because I have checked it using some sanity checks.

0

1 Answer 1

3
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

browser = webdriver.Firefox()
browser.get("url")
browser.find_the_element_by_id("add_button").click()

try:
    WebDriverWait(browser, 3).until(EC.alert_is_present(),
                                   'Timed out waiting for PA creation ' +
                                   'confirmation popup to appear.')

    alert = browser.switch_to.alert
    alert.accept()
    print("alert accepted")
except TimeoutException:
    print("no alert")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.