title: How to close newly constructed tab using selenium, chrome driver and python
body: <p>I am trying to scrape data from a website, there is an url which lands me a particular page, there we have links of some items, if I click on those links, it opens in a new tab, and I can extract data from there,</p>
  
  <p>But after extracting the data, I want to close the tab return to the main page and click on another link.</p>
  
  <p>I am using selenium with chrome web driver. I have tried following code:</p>
  
  <pre><code>#links which lands me to a new tab
  browser.find_element_by_xpath('//*[@id="data"]/div[1]/div[2]/a').click()
  
  browser.switch_to.window(browser.window_handles[0])
  browser.close() #it closes the main page, not the new tab I want
  and following code,
  browser.find_element_by_css_selector('body').send_keys(Keys.CONTROL + 'w')  #this code didn't work.
  </code></pre>
  
  <p>How to close newly constructed tab using selenium and python ?</p>