I am trying to open multiple tabs within the same browser window in Selenium. I am unable to open multiple tabs if I use a firefox profile. The tabs open normally without the profile. I have searched a lot , but the available answers are opening the tabs as separate windows. What I am after is multiple tabs in the same window in Firefox using a Firefox Profile.
System Information:
Windows7
Python 3.7
Firefox 84
Selenium 3.141
I have created a test firefox profile.
Code with Firefox Profile that doesn't work - tabs are opened as separate windows.
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.common.keys import Keys
binary = FirefoxBinary('C:\Program Files\Mozilla Firefox\firefox.exe')
firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
fp = webdriver.FirefoxProfile('C:\Users\john\AppData\Roaming\Mozilla\Firefox\Profiles\0kjv3jas.test')
fp.update_preferences()
first_link = "https://google.com"
second_link = "https://reddit.com"
driver = webdriver.Firefox(capabilities=firefox_capabilities, firefox_binary=binary, firefox_profile=fp, executable_path='C:\WebDriver\bin\geckodriver.exe')
driver.get(first_link)
driver.execute_script("window.open('" + second_link +"');")
Code without the Firefox profile works - create the tabs normally
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.common.keys import Keys
binary = FirefoxBinary('C:\Program Files\Mozilla Firefox\firefox.exe')
firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
first_link = "https://google.com"
second_link = "https://reddit.com"
driver = webdriver.Firefox(capabilities=firefox_capabilities, firefox_binary=binary, executable_path='C:\WebDriver\bin\geckodriver.exe')
driver.get(first_link)
driver.execute_script("window.open('" + second_link +"');")
References:
Open web in new tab Selenium + Python
Selenium multiple tabs at once
Python -- Opening multiple tabs using Selenium
Open multiple tabs in selenium using python
Open multiple tabs in selenium using python
Selenium Switch Tabs
https://gist.github.com/lrhache/7686903
https://www.lambdatest.com/blog/python-selenium-switch-tabs/
question from:
https://stackoverflow.com/questions/65877506/python-selenium-firefox-unable-to-open-multiple-tabs-when-using-firefox-profile 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…