Been using Mozilla firefox browser 78.15.0esr version to automate some document review on our company website with selenium. This involves opening firefox, going to the specified website to log in and proceed with a couple of clicks as I navigate through the website. However, there was a recent Mozilla browser update 91.3.0esr two days ago and since then, I have been unable to use selenium as I get a 'forbidden request' error page. I think there might be some additional preferences I need to add to the options. Please review my code below:
#importing packages
import time
from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
# Functions for click/send keys
def click_xpath(path, waittime = 240):
WebDriverWait(driver, waittime).until(EC.visibility_of_element_located((By.XPATH, path)))
WebDriverWait(driver, waittime).until(EC.element_to_be_clickable((By.XPATH, path)))
driver.find_element_by_xpath(path).click()
def sendkey_xpath(path, key, waittime = 240):
WebDriverWait(driver, waittime).until(EC.visibility_of_element_located((By.XPATH, path)))
WebDriverWait(driver, waittime).until(EC.element_to_be_clickable((By.XPATH, path)))
driver.find_element_by_xpath(path).clear()
driver.find_element_by_xpath(path).send_keys(key)
# get location of firefox driver
ffdriver = r'K:\mybasefolder\myfolder\Webdrivers\geckodriver-v0.29.1-win64\geckodriver.exe'
#storing my user email
user_email='myuseremail@gmail.com'
##### I THINK THE PROBLEM IS IN MY PREFERENCES/OPTIONS #########
# Enable use of selenium to company website
profile = webdriver.FirefoxProfile()
PROXY_HOST = "12.12.12.123"
PROXY_PORT = "1234"
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", PROXY_HOST)
profile.set_preference("network.proxy.http_port", int(PROXY_PORT))
profile.set_preference("dom.webdriver.enabled", False)
profile.set_preference('useAutomationExtension', False)
profile.update_preferences()
desired = DesiredCapabilities.FIREFOX
driver = webdriver.Firefox(firefox_profile=profile,
desired_capabilities=desired,
executable_path=ffdriver)
driver.get('https://companywebsite.com/SignIn.aspx')
click_xpath('//*[@id="ctl00_ContentPlaceHolder1_cmdSignInOpenId"]')
sendkey_xpath('//*[@id="username"]', user_email)