How to pass error without try catch in Python-Selenium?
<p>In my python-Selenium code, i should use many <strong>try-catch</strong> to pass the errors, and if i don't use it, my script doesn't continue.
for example if i don't use try catch, if my script doesn't find <code>desc span</code> i will have an error and i can't continue, </p>

<pre><code>    try :
        libelle1produit = prod.find_element_by_css_selector(('.desc span')).text  # libelle1produit OK
    except:
        pass
</code></pre>

<p>is there an alternative method for passing error? </p>

<blockquote>
  <p>is there an alternative method for passing error?</p>
</blockquote>

<p>Yes, To avoid <code>try-catch</code> and avoid error as well try using <code>find_elements</code> instead which would return either a list of all elements with matching locator or empty list if nothing is found, you need to just check the list length to determine that element exists or not as below :-</p>

<pre><code>libelle1produit = prod.find_elements_by_css_selector('.desc span')

if len(libelle1produit) &gt; 0 :
  libelle1produit[0].text
</code></pre>

python selenium exception web-scraping try-catch