Issue: Difficulty in opening multiple tabs with Firefox Profiles in Python SeleniumDescription: Encountering challenges

Need help with opening multiple tabs within the same browser window in Selenium. Struggling to achieve this when using a Firefox profile, as the tabs open separately without it. Despite extensive research, unable to find a solution that opens multiple tabs in the same Firefox window using a Firefox Profile.

System Information:

Operating System: Windows7
Programming Language: Python 3.7
Browser: Firefox 84
Selenium Version: 3.141

A test firefox profile has been created.

Code Attempt with Firefox Profile (tabs open 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 +"');")

Working Code without the Firefox profile:

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

Answer №1

To solve the issue, simply remove the Firefox profile as you are calling an empty profile which is unnecessary.

driver = webdriver.Firefox(capabilities=firefox_capabilities, firefox_binary=binary, options=options, executable_path='C:\\WebDriver\\bin\\geckodriver.exe')

If you do want to use a profile, you can do so by:

firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
fp = webdriver.FirefoxProfile()

fp.DEFAULT_PREFERENCES["frozen"]["browser.link.open_newwindow"] = 3

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Extracting Data from Aliexpress Purchase

After setting up a dropshipping account, I began manually placing orders on AliExpress. However, I wanted a more efficient way to track the shipped orders, so I decided to utilize Web Scraping with Python to compile all order information onto an Excel sp ...

Google AppEngine Endpoints encountered an error: Unable to retrieve service configuration (HTTP status code 404)

I am currently following the instructions outlined in the Quickstart guide. While working on this, I came across another query related to the same topic. I made sure that the env_variables section in my app.yaml file contains the correct values for ENDPO ...

In need of assistance transferring AWS Beanstalk Service to a different account

Looking for assistance in transferring an AWS Beanstalk setup to a different account. I initially set up an AWS Beanstalk Service under my own account within an AWS organization back in early June. Now that my internship with the organization has ended, I ...

What's with all the super fast content popping up on my browser when I begin my intern test?

Hello everyone, First of all, I want to express my gratitude in advance. I am currently executing a single functional test utilizing intern and local selenium. During the initiation of the test, the following sequence occurs: The Chrome browser is laun ...

Obtaining the clickable element's link in Selenium using Python

Downloading CSV files from a website is my goal, and I achieve this by utilizing the click() command in selenium automation. The elements exhibit the following structure code csvList = browser.find_elements_by_class_name("csv") for l in ...

Implementing a 10-second alert display in selenium

Task at Hand: I need to display the alert on my page for a few seconds to allow reading. Is there any function in Selenium Web-driver that can help with this? I am new to automation and have been learning about explicit waits. I tried using explicit wait ...

The date ticks format is not functioning properly with the where clause in the Python API for Firestore

Currently, I am utilizing Cloud Firestore in combination with a Python API. My objective is to create a where clause that will retrieve users based on the condition that the date their account was processed is earlier than their last updated date. The cha ...

Executing selenium tests within a dockerized django environment

When it comes to running tests, my usual approach involves launching a separate container using the following command: docker-compose run --rm web /bin/bash The 'web' container contains django, and I typically run py.test from a shell periodica ...

Instead of creating a new figure each time in a loop for imshow() in matplotlib, consider updating the current plot instead

I am facing a challenge where I need to save displayed images based on user input, but the issue lies in the fact that unlike plt.other_plots(), plt.imshow() does not overwrite the existing figure, rather it creates a new figure below the existing one. How ...

Gather information from a table using pagination features

Attempting to extract data from a paginated table using Selenium. The website being scraped does not have pagination in the URL. table = '//*[@id="result-tables"]/div[2]/div[2]/div/table/tbody' home = driver.find_elements(By.XPATH, &ap ...

Utilizing pandas to extract data within specified time ranges from a DataFrame

Looking at a segment of my dataFrame: fruit time 0 apple 2021-12-20 17:55:00 1 bannana 2021-12-23 05:13:00 2 apple 2021-12-20 17:55:00 I'm curious about how to extract data between specific timestamps, like from 5: ...

Python3 Program Running on Fedora Operating System with CGI-Script Environment

There is an issue with a CGI script in Python3 that I am encountering. Whenever I attempt to open files and use filenames containing German special characters like Ä or Ö, I receive an error due to encoding problems. The output of locale.getpreferredenc ...

Python: Utilizing Pandas Dataframes to Convert String Time in mm:ss to Total Minutes in Float Format

Assume I have a python dataframe that contains a column named "Time" which holds strings representing minutes and seconds. For example, the string 125:19 in the first row represents 125 minutes and 19 seconds. The datatype of this column is string. I am l ...

Create a new text file for each line in a list and copy the content into them individually

I am working with two lists that are the same length. One list contains file names I need to create, while the other is a 2D list with data that should be copied into text files named from the first list. Each element in the 2D list should have its own sep ...

What is the process to extract a data list from a frame, access and click on a link within the frame, and then proceed to click on another link within

I have uploaded a screenshot for your reference. I successfully logged into the website, but I am unable to navigate to a specific link and click on it. Here are the steps I need to perform: Retrieve the list of stocks from the frame and save it Select a ...

Error caused by missing element in Python Selenium when trying to locate the element with the tag <span>Incident

Upon attempting to click on the Incident tab highlighted in the image, an error is encountered. Below is the provided script for reference. from selenium import webdriver driver = webdriver.Chrome() driver.maximize_window() driver.get("https://*****.servi ...

Keystrokes malfunctioning on Firefox while functioning correctly on Chrome

I am currently in the process of developing a web scraping application using Python and Selenium to automate tasks on a server. Specifically, I am looking to create and schedule posts through CreatorStudio for sharing on Instagram. However, I have encounte ...

Struggled to generate parameterized test case in Python

Recently delving into the realm of Python, I find myself facing a challenge where I must create parametrized test cases. For instance, take a look at this Python 3 code snippet: import pytest from tests.fixtures import create_empty_database class TestCr ...

Incorporating stacktrace into Zephyr test execution with the help of Selenium

Our current framework includes a feature that automatically updates the test execution status in Zephyr. I am looking to enhance this by incorporating the stack trace for failed executions as a comment. However, I am having difficulty finding any documen ...

Retrieve deeply nested JSON objects that share a common value for a specified key

I am looking to extract all the nested JSON objects (nested dictionaries) from the given JSON data that have the same value for the account_id key. data = [ { "index": 1, "timestamp": 1637165214.7020836, &qu ...