Reputation: 247
I'm attempting to accept a javascript alert that pops up when deleting an element on my webpage. When I use accept_alert()
or dismiss_alert()
, I'm receiving the NoAlertPresentException: Message: u'no alert open\n
message. My code looks like this:
click_element(get_element_by_xpath('//*[@id="tracker"]/table[4]/tbody/tr/td[1]/a[1]'),wait=True)
accept_alert('Do you wish to delete?')
I have only been working with SST for 2 weeks, so I may be missing a simple solution.
The code that calls the javascript alert is as follows:
<a href="javascript: void(0);" onclick="return DeleteFood(1293652875);" class="track_remove" title="Remove">⊗</a>
Upvotes: 2
Views: 5016
Reputation: 51
try:
** your code **
except Exception as e:
try:
self.driver.switch_to.alert.accept()
print(e)
except NoAlertPresentException as e:
print(e)
Upvotes: 0
Reputation: 1956
Please try below after clicking on element which opens alert
try:
WebDriverWait(browser, 3).until(EC.alert_is_present())
alert = browser.switch_to_alert.accept()
print "alert accepted"
except TimeoutException:
print "no alert"
Upvotes: 0