Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Chromedriver launch new tab
#7
(Feb-13-2019, 02:08 PM)gahhon Wrote: So my concern is how to check if chrome running/exist? If so then how to launch new tab?
you only ever need to do this ever once in your program
driver = webdriver.Chrome(executable_path=r'chromedriver.exe')
Whereas driver.get(URL) you have to do numerous times to open each tab. Ive already explained how to switch tabs, and how to open a new tab earlier. driver.get(URL) will open the first tab if chrome is not open. If chrome is already open with a tab, then it will load the url on the first tab again with driver.get(url) regardless. To make a new tab you just switch windows before driver.get(url). The previous tab will remain until you close it and you will load and switch focus to the new tab. So there is no need for a check if chrome is running as driver.get(url) will open the first tab or a new tab depending on which window you are on.

As a side note. chromedriver will open a separate process than your chrome browser you are using. It is not meant to piggyback on your browser but open a new one being handled by selenium. chromedriver will have no relation to chrome on your computer.

# Opens a new tab
driver.execute_script("window.open()")
 
# Switch to the newly opened tab
driver.switch_to.window(driver.window_handles[1])
 
# Navigate to new URL in new tab
driver.get("https://google.com")
# Run other commands in the new tab here
 
You're then able to close the original tab as follows
 
# Switch to original tab
driver.switch_to.window(driver.window_handles[0])
 
# Close original tab
driver.close()
 
# Switch back to newly opened tab, which is now in position 0
driver.switch_to.window(driver.window_handles[0])
 
Or close the newly opened tab
 
# Close current tab
driver.close()
 
# Switch back to original tab
driver.switch_to.window(driver.window_handles[0])
Recommended Tutorials:
Reply


Messages In This Thread
Chromedriver launch new tab - by gahhon - Feb-10-2019, 03:57 PM
RE: Chromedriver launch new tab - by Larz60+ - Feb-10-2019, 06:31 PM
RE: Chromedriver launch new tab - by metulburr - Feb-10-2019, 06:39 PM
RE: Chromedriver launch new tab - by gahhon - Feb-11-2019, 02:55 PM
RE: Chromedriver launch new tab - by metulburr - Feb-11-2019, 09:21 PM
RE: Chromedriver launch new tab - by gahhon - Feb-13-2019, 02:08 PM
RE: Chromedriver launch new tab - by metulburr - Feb-13-2019, 10:35 PM
RE: Chromedriver launch new tab - by gahhon - Feb-14-2019, 04:09 PM
RE: Chromedriver launch new tab - by metulburr - Feb-15-2019, 04:56 PM
RE: Chromedriver launch new tab - by gahhon - Feb-16-2019, 07:39 AM
RE: Chromedriver launch new tab - by metulburr - Feb-16-2019, 01:39 PM
RE: Chromedriver launch new tab - by gahhon - Feb-16-2019, 07:00 PM
RE: Chromedriver launch new tab - by gahhon - Feb-16-2019, 10:04 PM
RE: Chromedriver launch new tab - by metulburr - Feb-17-2019, 12:04 AM
RE: Chromedriver launch new tab - by gahhon - Feb-17-2019, 04:13 PM
RE: Chromedriver launch new tab - by metulburr - Feb-17-2019, 06:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium undetected Chromedriver Bot Laurin0000 1 3,966 Apr-13-2023, 09:20 PM
Last Post: Clixmaster
  enable flash using selenium chromedriver Fre3k 1 4,248 Nov-27-2020, 12:15 PM
Last Post: JellyCreeper6
  WebDriverException: 'chromedriver' executable needs to be in PATH pyzyx3qwerty 9 12,637 Jun-09-2020, 05:43 PM
Last Post: Yoriz
  Selenium Chromedriver Automation Help lessthanthree 1 2,115 May-05-2020, 11:03 PM
Last Post: Larz60+
  How to identify chromedriver version? metulburr 2 7,459 Jun-13-2019, 11:37 PM
Last Post: metulburr
  chromedriver.exe issue gahhon 2 2,766 Feb-12-2019, 12:09 PM
Last Post: metulburr
  Selenium chromedriver and click action Gilles95 4 13,196 Feb-07-2018, 07:28 PM
Last Post: Gilles95

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020