Unable to interact with popup boxes using Python/Selenium web driver

151 views
Skip to first unread message

Ranjana Palanivel

unread,
May 15, 2018, 9:49:23 PM5/15/18
to seleniu...@googlegroups.com

Hi All,

I am writing the python/selenium script to automate web page.I am struck in a place wherein the popup appears,after clicking on 'OK' in the popup ,control should transfer back to web page.

I have tried with  below script.But still I am not able to proceed .Please help me out on this.
Can anyone please help me out on this.
def is_alert_present(self):
try:
self.driver.switch_to_alert()
self.assertEquals("Channel Created Succesfully")
except NoAlertPresentException as e:
return False

def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
assert "Channel Created Succesfully." in alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert.text
finally: self.accept_next_alert = True

def tearDown(self):
self.assertEqual([], self.verificationErrors)


--
Thanks & Regards

Ranjana P

Ranjana Palanivel

unread,
May 15, 2018, 10:07:30 PM5/15/18
to seleniu...@googlegroups.com
In addition to this ,switch_to_alert() function is getting striked out in my python script as soon as i use it in my Pycharm editor.
What could be the reason for this?
I am importing below two modules in my script
from selenium.common.exceptions import NoAlertPresentException
from selenium.common.exceptions import NoSuchElementException



Reed Xia

unread,
May 15, 2018, 11:06:52 PM5/15/18
to seleniu...@googlegroups.com
Hi Ranjana,

Not sure whether this answer in stakoverflow https://stackoverflow.com/questions/33466853/switch-to-alert-text-not-working?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa can help you, which said you may need wait for the Alert to be present first before using switch_to_alert().

Thanks,
Reed

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CANS_8%3Dv04t0A4-HNc5zAW5HWOBecf6_hbgqbxuJJVaapF_xi7g%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Reed Xia

unread,
May 15, 2018, 11:12:48 PM5/15/18
to seleniu...@googlegroups.com
And in my project, we usually code it in this way, just FYI

WAITER = new WebDriverWait();
try {
  WAITER.until(ExpectedConditions.visibilityOfElementLocated(BY_ID_ELEMENT)); // a instanc of BY
  // do something next..
} catch (Exception e) {
 // handle the exception..
}

  

To post to this group, send email to seleniu...@googlegroups.com.

Wayne

unread,
May 16, 2018, 10:34:22 AM5/16/18
to seleniu...@googlegroups.com
Way to go.

Ranjana Palanivel

unread,
May 16, 2018, 11:28:25 AM5/16/18
to Selenium Users
thanks for the solution..i hv used web driverwait .. i am able to proceed now.

Rakesh Raut

unread,
May 22, 2018, 9:38:28 AM5/22/18
to Selenium Users
HI Ranjana,

Try using below code instead of wait.
driver.switch_to.default_content()
Reply all
Reply to author
Forward
0 new messages