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 6696849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:23:24+00:00 2026-05-26T06:23:24+00:00

I am using Python for Selenium RC and I am using the following selenium

  • 0

I am using Python for Selenium RC and I am using the following selenium command:

self.se.get_attribute("CSS")

This command asserts when the respective CSS mentioned is not found on the webpage.

Is it possible for me to avoid the assert from happening and instead of the assert, another command is executed (On the condition that the assert has taken place)

self.se.get_text("another CSS")

Is there a way in python to capture the assert and just store its value and continue forward without terminating the program?
Could someone please help me with this?
Thanks

  • 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-05-26T06:23:25+00:00Added an answer on May 26, 2026 at 6:23 am

    If when 'CSS' is not valid, selenium raises a TypeError, you can catch and handle the exception in a try..except block:

    try:
        self.se.get_attribute("CSS")
    except TypeError:
        self.se.get_text("another CSS")
    

    This is an example of the “Easier to ask forgiveness (EAFP) than permission” coding style. The alternative is the Look before you leap (LBYL) coding style (see Nikita Barsukov answer for example). Both are possible, though I think EAFP is preferred in Python because doesn’t clutter the code with conditionals which may or may not fully capture the exceptional condition. EAFP is also fast when the exception is not raised too often. If the exception is raised often, LBYL may be preferrable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to scrape a webpage using Selenium (in Python) that is almost entirely
I'm using python, and I have a list of sets, constructed like this: list
I am using python lxml library to parse html pages: import lxml.html # this
(Using Python 3.1) I know this question has been asked many times for the
Using Python I can test my code in the terminal / command line by
using python 2.6.5 and python-ldap 2.3.10, I have the following problem: Under certain circumstances
I am trying automate a login process to my web application using Selenium-Python Client
I'm running Selenium 2.0b4dev on Selenium Grid in Ubuntu 10.04, using Python code to
I'm using Selenium 2/Webdriver with python and I want to click on the first
I am using Webdriver implemented through Python to run my selenium test scripts in

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.