Puedes simplemente crear un iterable con los drivers (referencias a las clases webdriver.x
) deseados y hacer uso de random.choice
:
import random
from selenium import webdriver
drivers = (webdriver.Firefox, webdriver.Safari, webdriver.Chrome)
driver = random.choice(drivers)()
driver.get("https://www.sitioweb.com/")
Si se necesitan pasar argumentos al constructor (como la ruta al driver) podemos hacer algo como:
import random
from selenium import webdriver
drivers = (
{
"driver": webdriver.Firefox,
"kwargs": {'executable_path': '/Users/drivers/geckodriver'}
},
{
"driver": webdriver.Safari,
"kwargs": {'executable_path': '/Users/drivers/chromedriver'}
},
{
"driver": webdriver.Chrome,
"kwargs": {'executable_path': '/Users/drivers/safaridriver'}
}
)
rand_d = random.choice(drivers)
driver = rand_d["driver"](**rand_d["kwargs"])
driver.get("https://www.sitioweb.com/")