I have my old python script for some work intranet sites we still have not upgraded that run in IE compatibility within edge. I changed it a bit to update since IE is no longer available after os updates but it only opens a automated window without a profile so it doesn't use the access the profile has to intranet sites
All my imports incase its needed:
from decimal import Decimal
from sys import argv
from time import sleep
import os
import shutil
import traceback
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.common.exceptions import InvalidElementStateException, TimeoutException
from selenium.webdriver.common.by import By
import selenium.webdriver.support.ui as ui
import xlrd
Original function
def create_browser():
ie_options = webdriver.IeOptions()
# run edge in IE mode
# would stick to regular instance of edge in ie compatibility mode
ie_options.attach_to_edge_chrome = True
ie_options.edge_executable_path="C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
return webdriver.Ie(options = options)
New function
def create_browser():
edge_options = webdriver.EdgeOptions()
edge_options.add_argument("--ie-mode-test")
#edge_options.add_argument("--start-maximized")
edge_options.add_argument(r"--user-data-dir=C:\Users\%USERNAME%\AppData\Local\Microsoft\Edge\User Data")
edge_options.add_argument("--profile-directory=Default")
service = Service(executable_path=r"C:\Webdrivers\msedgedriver.exe")
return webdriver.Edge(service=service, options=edge_options)
Am i missing something? is there something in selenium that I'm overlooking? I keep hitting errors saying:
Message: session not created
from unknown error: cannot create default profile directory
--user-data-dir=C:\Users\%USERNAME%\AppData\Local\Microsoft\Edge\User Data. Try a hard-coded path instead of relying on env variables.