I have a python script that runs different selenium WebDrivers which have been exported into python. The script and webdrivers do what I want them to do. When the script executes a webdriver, the webdriver will do what it needs to then go back and continue the script but then it will pause and firefox will pop up again and execute the same webdriver task again. This doesn't affect the results I get from the webdrivers or the script but it increases my run-time significantly.
After the first exectution of a webdriver the shell will return:
Ran 1 test in 192.680s OK
However, when it repeats the webdriver unexpectedly it only returns a period "."
Here is the code for the webdriver,
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
class WebdriverViewas(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = #website I'm interested in visiting
self.verificationErrors = []
self.accept_next_alert = True
def test_webdriver_viewas(self):
#Here I just tell the webdriver what to do, I doubt this is causing the problem
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException, e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = 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.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__=='__main__':
try:
unittest.main()
except SystemExit as inst:
if inst.args[0] is True: # raised by sys.exit(True) when tests failed
raise
I suspected the problem could be solved with the unittest module but I've found nothing in the research I've done nor have I been able to find anyone with a similar problem.
python 1.py
where 1.py - is your code withself.driver.get(url)
in the body of test. One run as expected – Alexander Petrovich Sep 24 '13 at 18:38python 1 .py
are you running it from the python shell? I tried importing webdriver.py as a module and then using the code whereself.driver.get(url)
as a separate function but that didn't work either. – seeiespi Sep 25 '13 at 3:56