testing - Check if any alert exists using selenium with python -


i'm trying write test selenium in python language web page manages users. in page can add role users , if role exists while adding it, alert raises. don't know if alert javascript alert or element of web page. want automatically check existence of alert, because checking role in list wastes time , has enormous load. tried this:

browser = webdriver.firefox() browser.get("url") browser.find_the_element_by_id("add_button").click() try:     alert = browser.switch_to_alert()     alert.accept()     print "alert accepted" except:     print "no alert" 

but didn't work , got "unexpectedalertpresentexception". tried this:

browser = webdriver.firefox() browser.get("url") browser.find_the_element_by_id("add_button").click() s = set(browser.window_handles) s.remove(browser.current_window_handle) browser.switch_to_window(s.pop())  

but got same exception. additionally, tried access alert firebug check if can access properties, right click disabled. need solution quickly, in other languages. can understand approach anyway. appreciate help.

what set conditional delay webdriverwait before point expect see alert, switch it, this:

from selenium import webdriver selenium.webdriver.support.ui import webdriverwait selenium.webdriver.support import expected_conditions ec 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 pa creation ' +                                    'confirmation popup appear.')      alert = browser.switch_to.alert()     alert.accept()     print "alert accepted" except timeoutexception:     print "no alert" 

webdriverwait(browser,3) wait @ least 3 seconds supported alert appear.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -