0

I'm trying to automate a procedure on a really old IE-only webpage and, at one point, it raises an alert.

I can't inspect it using IE (or don't know how) but there's only an "accept" button (actually an image) and the alert text can't be copied (not sure why).

I'm using selenium with the IE drivers and i can't get past this alert.

Selenium IS detecting the alert, but when i check its contents i get nothing. I've tried accepting the alert with

alert_obj = self.br.switch_to.alert
alert_obj.accept()

and also

.dismiss();
.send_key(Keys.ENTER)

and some other things. Am i missing something?

photo of alert:

enter image description here

6
  • Can you share the screenshot of alert? Commented Jul 12, 2018 at 19:42
  • Just did, sorry! Commented Jul 12, 2018 at 19:45
  • Returned "unable to find element". Is there any way i can inspect this pop-up using IE? I'm pressing F12 but nothing happens. Commented Jul 12, 2018 at 19:49
  • Did you check this? Commented Jul 12, 2018 at 19:54
  • Not really, i can use the developer tools perfectly fine in other pages. It's just that this popup freezes the rest of the browser. I can't even close the original browser! Commented Jul 12, 2018 at 20:00

4 Answers 4

0

alerts are generic dialog boxes that include a text and ok button. If your alert has an image as button, then it is not an alert, but something else. I don't know what it is, but not an alert.

This is an alert:

ALERT DIALOG IN INTERNET EXPLORER

Sign up to request clarification or add additional context in comments.

6 Comments

Hmmm, yeah, it doesn't look like that. However, when it pops up i checked for all the current handles and i only found one, which means that Selenium only had one window open (right?) Also, when trying to send an enter key i got an error that said basically "Hey, this is an alert, i can't do that". But thank you very much!
@LucasCioffi from the image it seems a floating div added by javascript. Try using the inspector from your browser (press F12) to see how the element is added to the page.
@LucasCioffi your alert may look like a new window but in fact is just another new element created in the same page.
i tried but i can't :( when the pop-up appears i can't do anything else besides clicking "ok", and then it redirects to another page. THe entire browser freezes.
@LucasCioffi anyway, selenium alert handling functions only work with real alerts, and what you have is not one - that's why selenium can't deal with it as alert. It is hard for me to tell what it is without looking at the page myself - but I can assure you any alert-related function won't work with it because it is not an alert. I hope that answers your question and points you to the right direction
|
0

If this popup is an alert, you can handle it while initializing driver itself. Below is C# Code for that:

InternetExplorerOptions options = new InternetExplorerOptions
{               
   UnhandledPromptBehavior = UnhandledPromptBehavior.Accept,                   
};                                
driver = new InternetExplorerDriver(options);

Above code should handle alert. if not, try adding this code before creating driver instance.

 options.AddAdditionalCapability("browserstack.ie.enablePopups", "accept");

Comments

0

This question is a possible duplicate of:

How to close yet another chrome popup using python selenium

To moderators: I tried to flag this question as Duplicate, but then, when I typed "How to close yet another chrome popup using python selenium" into the search bar it found no results.

2 Comments

Doesn't work for me :( Selenium returns a "no alert active" error BUT i can't even quit the browser when this thing appears.
Instead of send_keys(keys.ENTER), try send_keys(u'\ue007')
0

I somehow managed to do it.

I tried everything and everything was buggy. I even had to use this weird loop because just using a time.sleep() call was bugging things up. I really don't know what happened. Sometimes when entering the page the pop-up handle would appear and sometimes not. Sometimes in the wrong place. Sometimes it wouldn't close properly. I tried a pile of different ways and this one seems to work:

Here's what i did:

    #Saves ID from original window
    janelaOriginal = self.br.current_window_handle
    #Go to the website
    self.br.get(url)

    #waits 2.5 seconds for the pop-up (time.sleep bugs)
    i = 0
    while(i < 25):
        i += 1
        time.sleep(0.1)
        #is pop-up open?:
        if(len(self.br.window_handles)>1):
            #handle sometimes appears in the wrong place so this is necessary:
            if(janelaOriginal==self.br.window_handles[0]):
                self.br.switch_to_window(self.br.window_handles[1])
            else:
                self.br.switch_to_window(self.br.window_handles[0])
            #close the pop-up and go back to the original window
            self.br.close()
            self.br.switch_to_window(janelaOriginal)
            #do stuff
            return
    #do other stuff

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.