2

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>
Brenda
  • 247
  • 1
  • 4
  • 14

3 Answers3

1

You should call click_element with wait=False see this

So, something like the following should work

click_element(get_element_by_xpath('//*[@id="tracker"]/table[4]/tbody/tr/td[1]/a[1]'),wait=False)
accept_alert('Do you wish to delete?')
Saifur
  • 16,081
  • 6
  • 49
  • 73
  • Still receiving the `NoAlertPresentException`. – Brenda Dec 05 '14 at 15:01
  • 1
    I have taken a look at the APIs again and seems like SST doesn't require `switch to alert`. So two possible solutions can be passing both parameter `accept_alert` requires. such as `accept_alert(expected_text=None, text_to_write=None)` if you don't have to pass `text` or simply `accept_alert()` – Saifur Dec 05 '14 at 15:40
  • the first `accept_alert(expected_text=None, text_to_write=None)` worked. Thank you! – Brenda Dec 05 '14 at 15:46
0

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"
Rupesh Shinde
  • 1,933
  • 12
  • 22
  • That brings up an `AssertionError: Could not identify element: 0 elements found` – Brenda Dec 05 '14 at 14:57
  • Now receiving `AttributeError: 'module' object has no attribute 'TimeoutException'`. I did an `import selenium.common` to pull the exception. So, I'm not sure why I'm getting this. Is it because SST doesn't always play nice with selenium code? – Brenda Dec 05 '14 at 15:10
  • I changed it to `alert = browser.switch_to_alert.accept()` and still receiving the `AttributeError: 'module' object has no attribute 'TimeouException'` – Brenda Dec 05 '14 at 15:18
  • I think we have to check the imports in the code. Please check below link http://stackoverflow.com/questions/1250103/attributeerror-module-object-has-no-attribute – Rupesh Shinde Dec 05 '14 at 15:19
  • My imports are: `import unittest from sst.actions import * from sst import cases, config, browsers import selenium.common` – Brenda Dec 05 '14 at 15:21
0
    try:
        ** your code **

    except Exception as e:
        try:
            self.driver.switch_to.alert.accept()
            print(e)
        except NoAlertPresentException as e:
            print(e)