Achieving permanent proxy settings in Firefox Webdriver: A step-by-step guide

As Geckodriver does not allow direct proxy settings, I will manually adjust it with the following code snippet:


from selenium import webdriver

myProxy = "xxxxxxxxx:yyyy"
ip, port = myProxy.split(":")

profile = webdriver.FirefoxProfile()
profile.set_preference('network.proxy_type', 5)
profile.set_preference('network.proxy.http', 'xxxxxxxxx')
profile.set_preference('network.proxy.http_port', yyyy)
profile.update_preferences()

driver = webdriver.Firefox(firefox_profile=profile)
driver.get('http://www.google.co.th')
time.sleep(3)
driver.close()

After executing this code snippet, Firefox will be in proxy mode.

However, when running the script through Robot Framework, which also uses Geckodriver, the browser does not update to use the proxy as expected.

I am looking for a solution to permanently set the proxy in Geckodriver.

Answer №1

Utilizing the Open Browser keyword from SeleniumLibrary allows for customization of preferences similar to Python scripting.

For instance, consider this test that opens a browser with specific options every time:

  1. Proxy HTTP port set to 777.
  2. Proxy type set to "5".
  3. Proxy HTTP set to "xxxxxxxxx".

*** Settings ***
Library    SeleniumLibrary

*** Test Cases ***
Test
    Open Browser    http://example.com    Firefox   ff_profile_dir=set_preference("network.proxy_type", "5");set_preference("network.proxy.http", "xxxxxxxxx");set_preference("network.proxy.http_port", 777)   # Defining profile using FirefoxProfile methods.
    Sleep    1 min    reason=Verify proxy settings manually in the opened browser.

Values verified on Firefox's about:config page during sleep:

https://i.stack.imgur.com/w5j6c.png

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

Python deal with JSON floating with leading zeros

Is there a way to format floats with trailing zeros using the Python (3.5) json standard library? import json to_be_serialized = {'something': 0.020} print(json.dumps(to_be_serialized)) {"something": 0.02} # expected output: {"something": 0.020 ...

Error encountered: The method WebElement.click of <selenium.webdriver.firefox.webelement.FirefoxWebElement has failed to execute

Recently, I created a Python script that automatically logs into my email account and sends messages. It was working fine after testing, but then I decided to make some changes to simplify it - like adding one-liners and reducing the number of local variab ...

I encountered an error in my discord.py main.py code, where a 'NoneType' object does not have the attribute 'send'

Every time I attempt to utilize the channel.send() function in discord.py to send a message, I encounter an error stating "'NoneType' object has no attribute 'send'. Can someone please offer assistance? The issue stems from this sectio ...

Using Pandas to group and count values in complex strings with multiple repeat occurrences

Let's consider a df structured as follows: stringOfInterest trend 0 C up 1 D down 2 E down 3 C,O up 4 C,P ...

Creating a Python dictionary with file names as keys: A step-by-step guide

My goal is to send all files located in a specific folder on my local disk to a designated web address using Requests and Glob. Each time I upload a new file to the URL, I intend to update a dictionary with a new entry consisting of the "file name (key)" a ...

What is the best way to eliminate the specific element containing our desired word from the webpage data extracted through selenium?

After scraping 6 elements from a website using the Selenium find_element(By.XPATH) module, I stored these elements in a list. I then converted these elements into text and searched on Google. However, due to the ever-changing nature of the elements, somet ...

What is the equivalent of the DataSource attribute for mstest in .NET Core?

Is DataSource attribute supported in .NET Core projects of MSTest? If not, what is the alternative? For more information, visit: https://learn.microsoft.com/en-us/visualstudio/test/how-to-create-a-data-driven-unit-test?view=vs-2019 Note: In .NET Core, th ...

Use the inline IF statement to adjust the icon class depending on the Flask variable

Is it feasible to achieve this using the inline if function? Alternatively, I could use JavaScript. While I've come across some similar posts here, the solutions provided were not exactly what I expected or were implemented in PHP. <i class="f ...

Creating a time restriction for the SFTP file transfer operation in the Paramiko module

Utilizing Paramiko's SFTP client, I am attempting to download a large file from a remote server to a client (specifically, a get operation). The file size is around 1GB and I want the get operation to timeout if it takes more than 10 seconds. However ...

Initializing JBrowserDriver can be quite time-consuming, often taking over a minute to complete

Currently, I am utilizing JBrowserDriver to capture screenshots from various pages. However, a noteworthy issue arises when I initialize the driver variable as it takes a considerable amount of time, approximately 70 seconds. JBrowserDriver driver = new ...

A Guide to Replacing a json Field with Null and Inserting it into a PostgreSQL Database

I have thoroughly examined the available options discussed in this context, but I find that most of them do not adequately address my specific situation. In my scenario, I import this information into a database where the field is designated as SMALLINT. H ...

Change to the parent frame using webdriver

I am facing an issue while trying to switch to the parent frame or iFrame using webdriver.js. Although I have implemented a function that works, it only goes up to the second level of frames. When attempting to switch to the parent frame from a deeper fr ...

What is the best way to configure PyDev to automatically format code with a specific character limit per line?

I rely on PyDev for Python coding within Eclipse. Can PyDev be configured to automatically format my code and restrict the maximum number of characters per line? ...

Recursively insert a number into a sorted list

How can I insert my_num into the given list in the correct position using the provided structure? I've tried but am not getting the expected results, what should I do? my_lst = [1, 3, 5] my_num = 4 def new_number(lst): return lst def plus_nu ...

Executing tasks concurrently in Snakemake rule

Apologies if this question seems basic, but I'm still grappling with the complexities of Snakemake. I have a folder full of files that I need to process in parallel using a rule (i.e. running the same script on different input files simultaneously). ...

Automate text input using Selenium and Python: a guide to filling in a Wikipedia textarea

I'm seeking help with Selenium - specifically, how to input text into a textarea (wiki textarea). The original HTML is provided below. Your assistance in figuring this out would be greatly appreciated. Thank you! <textarea class="textarea long-f ...

I'm having trouble getting the play command to work on my Discord bot using Wavelink. Does anyone know how to troubleshoot and fix this

This is the play command for my bot: @client.tree.command(name="play", description="Play some music") @app_commands.describe(musicname="The name of the music you want to play") async def play(interaction:Interaction, musicname ...

During the installation of bcrypt using npm, an error occurred with gyp related to

Encountering errors while attempting to install bcrypt on Windows 10 with node:v6.7.0, npm:v4.0.1, and node-gyp:v3.4.0. Even though python27 and python35-32 are both in my path, I am facing the following issues: D:\myApp\node_modules\bc ...

What is the best way to determine the correct xpath to locate and access all profiles on a webpage utilizing Selenium and Python?

As a beginner in the world of programming, I have embarked on an exciting journey to create a test software for automating data retrieval from a website. Despite my enthusiasm, I am encountering challenges in defining the xpath that would allow me to locat ...

Need assistance with Python code that retrieves information from a CSV file and inserts it into a different CSV file?

I need assistance with data migration. The old application's data has been exported as a CSV file, but we cannot import this directly into the new application. I need to create a new CSV template that aligns with the new application and then import so ...