Python, use proxy for Selenium test automation

Problem:

You need to make a test script using Selenium with python in a raspberry pi and you don't know how to use it.

Solution:

Copy and paste the following code in your py file:

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

from fp.fp import FreeProxy

import os


#proxy connection 

try:

 v_proxy = FreeProxy(timeout=0.3, anonym=False, rand=True).get()

 if(v_proxy!=""):

  print(' Using Proxy: ', v_proxy)

except Exception as e:

 print(' Error:', e)


#load data

chrome_options = webdriver.ChromeOptions()

chrome_options.add_argument('--proxy-server=%s' % v_proxy)

chrome_options.add_argument("--incognito")

driver = webdriver.Chrome(options=chrome_options)

driver.get("https://www.whatismyip.com/es/")