title: how to bypass error in selenium python web scraping
body: <p>I have written the following code for web scraping. the code without the if else loop part works fine, that i intend to do. I have a list of urls which i want to scrape and if in any url the element that doesnt exist, then i have to bypass that url and move on to the next. I achieved bypassing the url that has no element, but my normal scraping then doesnt work in the else loop as it should.
  any help guys?</p>
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.action_chains import ActionChains
  import time
  from selenium.common.exceptions import TimeoutException
  from selenium.common.exceptions import NoSuchElementException  
  
  urls= [
  'http://www.marketsmojo.com/Stocks?StockId=1002687&amp;Exchange=0'
  ]
  f= open(&quot;lolly.txt&quot;,&quot;a+&quot;)
  browser=webdriver.Chrome()
  browser.maximize_window()
  browser.get('http://www.marketsmojo.com/Stocks?StockId=565016&amp;Exchange=0')
  browser.find_element_by_xpath(&quot;//*[@id='step-0']/a/i&quot;).click()
  for url in urls:
      browser.get(url)
      browser.execute_script(&quot;window.scrollTo(10,9500);&quot;)
      browser.implicitly_wait(2000)
      if browser.find_element_by_xpath(&quot;//div[contains(.,' No Shareholding data available ')]&quot;):
          continue
      else:
          add=browser.find_element_by_css_selector('#btnShareholdingDashboardFullDetails')
          SearchButton = browser.find_element_by_css_selector('#btnShareholdingDashboardFullDetails')
          Hover = ActionChains(browser).move_to_element(add).move_to_element(SearchButton)
          Hover.click().perform()
          browser.find_elements_by_css_selector('#allquarters &gt; div &gt; table')
          add1 = browser.find_element_by_css_selector('#AllQuarters')
          SearchButton1 = browser.find_element_by_css_selector('#AllQuarters')
          Hover1 = ActionChains(browser).move_to_element(add).move_to_element(SearchButton1)
          Hover1.click().perform()
          data = []
          for tr in browser.find_elements_by_css_selector('#allquarters &gt; div &gt; table'):
              ths = tr.find_elements_by_tag_name('th')
              tds = tr.find_elements_by_tag_name('td')
              if ths: 
                  data.append([th.text for th in ths])
              if tds: 
                  data.append([td.text for td in tds])
              f.write(str(data))
  
      
  browser.quit()
  </code></pre>