0

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
2
  • The error is shown: cannot create default profile directory, possibly there is something wrong with the path: --user-data-dir=C:\Users\%USERNAME%\AppData\Local\Microsoft\Edge\User Data. Try a hard-coded path instead of relying on env variables. Commented Jan 21 at 14:06
  • you might check here: selenium.dev/documentation/webdriver/browsers/internet_explorer ...but I'm not sure you can set a profile using Edge. You might try creating a fresh new profile manually, logging that one in, and then setting the profile to the new one in options. Commented Jan 21 at 19:01

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.