Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
How do you run your test? I just did it with simple python 1.py where 1.py - is your code with self.driver.get(url) in the body of test. One run as expected –  Alexander Petrovich Sep 24 '13 at 18:38
    
I use execfile("C\webdriver.py") within the script. Where webdriver is basically the code presented above. I'm not sure what you're referring to by python 1 .py are you running it from the python shell? I tried importing webdriver.py as a module and then using the code where self.driver.get(url) as a separate function but that didn't work either. –  seeiespi Sep 25 '13 at 3:56
    
Any luck getting this issue sorted out? –  duhaime Jan 25 at 17:13
    
Yes, but in order to solve it I had to take it out of a class and run it like a regular command. I used almost the same commands as I did within the class so I'm not sure why it works outside of the class format rather than within. In any case it didn't really sacrifice efficiency or functionality so the solution worked fine for me. I will update if I ever run into a similar problem in the future and solve it another way. –  seeiespi Apr 2 at 20:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.