Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8974693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:43:54+00:00 2026-06-15T18:43:54+00:00

I have a selenium webdriver test case exported to python using selenium IDE. Then

  • 0

I have a selenium webdriver test case exported to python using selenium IDE. Then wanted to add some additional functionality so inserted custom code in between the selenium test case.

Now the problem is – if i make a mistake or the custom written python code returns error – still the selenium test case continues to execute

Whereas i want the selenium test case execution to be stopped if there is such error. Have replicated the scenario below with a simple google search followed by a log movement code using shutil module

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
import os, shutil

class SeleniumException(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(30)
        self.base_url = "https://www.google.co.in/"
        self.verificationErrors = []

        self.attachment = 1
        self.file_source_location = "F:\\python_test\\logfiles\\"
        self.file_move_location = "F:\\logfiles_back\\"

    def test_selenium_exception(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element_by_id("gbqfq").clear()
        driver.find_element_by_id("gbqfq").send_keys("Check this out")
        if self.attachment:
            try:
                for contents in os.listdir(self.file_source_location):
                    src_file = os.path.join(self.file_source_location, contents)
                    dst_file = os.path.join(self.file_move_location, contents)
                    shutil.move(src_file, dst_file)
                print'files_moved_success'
                driver.find_element_by_link_text("check out - definition of check out by the Free Online Dictionary ...").click()
            except Exception as e:
                print e

    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException, e: return False
        return True

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

In this code – If the movement from logfiles to logfiles_back fails due to reasons like wrong path …Etc the catch block is executed and i want the selenium test case to quit reporting an error

What is happening right now is it reports the error and completes the execution of the test case

How to make this possible ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:43:55+00:00Added an answer on June 15, 2026 at 6:43 pm

    If you want to raise the actual exception that was triggered, you can call raise by itself, which will raise the last active exception:

    try:
        for contents in os.listdir(self.file_source_location):
            src_file = os.path.join(self.file_source_location, contents)
            dst_file = os.path.join(self.file_move_location, contents)
            shutil.move(src_file, dst_file)
        print'files_moved_success'
        driver.find_element_by_link_text("check out - definition of check out by the Free Online Dictionary ...").click()
    except Exception as e:
        print e
        raise # Raise the exception that brought you here 
    

    If you don’t want a traceback and just want to exit, you can also call sys.exit(1) (or whatever error code you want to use) after print e:

    import sys
    # ...
    try:
        for contents in os.listdir(self.file_source_location):
            src_file = os.path.join(self.file_source_location, contents)
            dst_file = os.path.join(self.file_move_location, contents)
            shutil.move(src_file, dst_file)
        print'files_moved_success'
        driver.find_element_by_link_text("check out - definition of check out by the Free Online Dictionary ...").click()
    except Exception as e:
        print e
        sys.exit(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some tests created using Selenium WebDriver. When I run them using IE
I have a C# unit test using Selenium WebDriver to test to see if
I'm using selenium webdriver to test our website. We also have a browser plugin/extension
Using capybara 1.0.0 and selenium-webdriver 0.2.0 and in a test I have something like
We were writing a Selenium test core by using Python webdriver. The main idea
I have some Selenium 2 Webdriver test cases for Firefox and Internet Explorer 9.
I've been scraping a website using Selenium (Python Webdriver). When I try to have
I have been using Selenium (WebDriver) for some time now, utilising Microsoft Team Foundation
I have a selenium test that looks like require 'spec_helper' driver = Selenium::WebDriver.for :firefox
I have the following code in python from selenium import webdriver from selenium.webdriver.common.by import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.