1

I'm very new to python so I'm a noob at this, I've tried searching but nothing seems to work(at least what I've seen and tested). I have also tried "webbrowser.get(chrome_path).open(url)" which did not really help me. Anyway heres the code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import webbrowser

#path for the driver
driver  = webdriver.Chrome(executable_path="C:\mydriver\chromedriver")

driver.get("https://www.google.com")
driver.execute_script("window.open ('https://www.google.com', 'new window')")
driver.switch_to.window(driver.window_handles[0])

driver.execute_script("window.open ('https://www.bing.com','https://www.facebook.com', 'new window')")
driver.switch_to.window(driver.window_handles[1])

2 Answers2

0

Selenium is a tool for testing GUIs in browsers. From your question it sounds like you just want to open a few browser windows. Why not just run Chrome/IE/Firefox/... directly from the commandline in Python.

import subprocess
subprocess.Popen("start chrome /new-tab www.google.com", shell=True)
Gijs Wobben
  • 1,974
  • 1
  • 10
  • 13
  • Yes thank you, but how would I open a separate window with that? Because I need at least 40 tabs on each window (saying that I decide to have 10 windows in total or more) so I can go in and get my 'data', because waiting for every single tab to load on one window would take hours, so running them all simultaneously on different tabs would decrease time dramatically. – Ahmad Hassan Nov 20 '20 at 08:50
0

You need to initialize webdriver instance for every new browser window:

from selenium import webdriver

urls = ['https://www.google.com', 'https://www.facebook.com', 'https://www.twitter.com']
for url in urls:
    driver = webdriver.Chrome()
    driver.get(url)
Alderven
  • 7,569
  • 5
  • 26
  • 38
  • Yes, that is a sufficient method, but I need to open multiple tabs so I can go in and get my 'data', and not just one tab which directs to a new URL because I need to reduce time as opening 400+ tabs in 1 window would take a lot of time so to reduce time, let's say for 400 tabs I would need 40 tabs for 10 windows and running them simultaneously on different tabs would decrease. – Ahmad Hassan Nov 20 '20 at 08:58