Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: BrowserFactory::LaunchEdgeInIEMode always creates temp user-data-dir so we cannot use Default profile #10968

Closed
sohrabtowfighi opened this issue Aug 22, 2022 · 10 comments
Labels
G-msedgedriver Requires fixes in MSEdgeDriver I-defect

Comments

@sohrabtowfighi
Copy link

What happened?

I am trying to run IE in Edge using the default user profile as shown in the code below.
It never works.
I realized that the iedriver java code hardcodes that a temporary directory is needed.
This is related to pull request 10006

The relevant code is found in selenium/cpp/iedriver/BrowserFactory.cpp
See the function, void BrowserFactory::LaunchEdgeInIEMode

// create a temporary directory for IEDriver test
std::wstring temp_dir;
if (CreateUniqueTempDir(temp_dir)) {
LOG(TRACE) << L"Using temporary folder " << LOGWSTRING(temp_dir) << ".";
executable_and_url.append(L" --user-data-dir=" + temp_dir);
this->edge_user_data_dir_ = temp_dir;
}

It does not make sense to me why we need to hard code the user-data-dir. It is important that selenium be able to operate using a specified profile. The script below intentionally comments out the path to the msedge.exe file so that an error is raised. In the error output, it is clear that a temporary directory is being used as the user-data-dir

How can we reproduce the issue?

from selenium import webdriver
import os
import sys
ieOptions = webdriver.IeOptions() 
pwd = os.path.dirname(sys.argv[0])
web_driver_path = os.path.join(pwd,'IEDriverServer.exe')    
msedge_user_profile = ('C:/Users/' + os.getlogin() + 
                       '/AppData/Local/Microsoft/Edge/User Data/')
ieOptions.add_additional_option('user-data-dir', msedge_user_profile)
ieOptions.add_additional_option("profile-directory", "Profile 1")
ieOptions.attach_to_edge_chrome = True
#ieOptions.edge_executable_path = (
#             'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe')

Relevant log output

File "C:\Users\admin\Desktop\pyCC\test.py", line 18, in <module>
    driver = webdriver.Ie(executable_path=web_driver_path, options=ieOptions)
  File "C:\Users\admin\anaconda3\lib\site-packages\selenium\webdriver\ie\webdriv
er.py", line 110, in __init__
    super().__init__(
  File "C:\Users\admin\anaconda3\lib\site-packages\selenium\webdriver\remote\web
driver.py", line 270, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\admin\anaconda3\lib\site-packages\selenium\webdriver\remote\web
driver.py", line 363, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\admin\anaconda3\lib\site-packages\selenium\webdriver\remote\web
driver.py", line 428, in execute
    self.error_handler.check_response(response)
  File "C:\Users\admin\anaconda3\lib\site-packages\selenium\webdriver\remote\err
orhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unexpected error
 launching Internet Explorer. CreateProcess() failed for edge with the following
 command: msedge.exe --ie-mode-force --internet-explorer-integration=iemode --us
er-data-dir=C:\Users\admin\AppData\Local\Temp\IEDriver-0d804d6b-746b-4dfe-9393-5
d44c3bb0984 --no-first-run --no-service-autorun --disable-sync --disable-feature
s=msImplicitSignin --disable-popup-blocking http://localhost:58342/

Operating System

Windows 10

Selenium version

4.4.3

What are the browser(s) and version(s) where you see this issue?

MS Edge 104.0.1293.63 (Official build) (64-bit)

What are the browser driver(s) and version(s) where you see this issue?

IEDriver 4.3.0.0

Are you using Selenium Grid?

No response

@github-actions
Copy link

@sohrabtowfighi, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@diemol diemol added G-msedgedriver Requires fixes in MSEdgeDriver and removed needs-triaging labels Aug 22, 2022
@github-actions
Copy link

Hi, @sohrabtowfighi.
This issue has been determined to require fixes in MSEdgeDriver
or in the IE Mode in Edge.

You can see if the feature is passing in the Web Platform Tests.

If it is something new, please create an Issue with the MSEdgeDriver team.

Feel free to comment the issues that you raise back in this issue. Thank you.

@sohrabtowfighi
Copy link
Author

Hi @diemol
The task is not related to MSEdgeDriver.
The task is related to the IEDriverServer.
The relevant code is found in selenium/cpp/iedriver/BrowserFactory.cpp

@diemol
Copy link
Member

diemol commented Aug 22, 2022

They are now being kind enough to help us maintain the IEDriver. That is why.

@titusfortner
Copy link
Member

It makes sense that it defaults to a temp directory so that it behaves like other drivers. I agree that there should be a way to specify this. A PR to add that feature would be appreciated.

@sohrabtowfighi
Copy link
Author

It makes sense that it defaults to a temp directory so that it behaves like other drivers. I agree that there should be a way to specify this. A PR to add that feature would be appreciated.

Please say this here:

MicrosoftEdge/EdgeWebDriver#29

@titusfortner
Copy link
Member

Microsoft already knows what they are doing there. I was mostly responding to:

It does not make sense to me why we need to hard code the user-data-dir

@sohrabtowfighi
Copy link
Author

sohrabtowfighi commented Aug 23, 2022 via email

@sohrabtowfighi
Copy link
Author

FYI, I figured out a workaround. This was posted here.

I was able to get around this issue with some edits to the browser factory code. I have provided some of the surrounding code so that you can ctrl-f to the relevant section.

// These flags force Edge into a mode where it will only run MSHTML
executable_and_url.append(L" --ie-mode-force");
executable_and_url.append(L" --internet-explorer-integration=iemode");

// THIS IS NEW
// create a temporary directory for IEDriver test if --user-data-dir is not already
// supplied
std::wstring temp_dir;
if (StringUtilities::ToString(browser_command_line_switches_).find("--user-data-dir") == std::string::npos) {
  if (CreateUniqueTempDir(temp_dir)) {
    LOG(TRACE) << L"Using temporary folder " << LOGWSTRING(temp_dir) << ".";
    executable_and_url.append(L" --user-data-dir=" + temp_dir);
    this->edge_user_data_dir_ = temp_dir;
  }
}

executable_and_url.append(L" --no-first-run");
executable_and_url.append(L" --no-service-autorun");
executable_and_url.append(L" --disable-sync");
executable_and_url.append(L" --disable-features=msImplicitSignin");
executable_and_url.append(L" --disable-popup-blocking");

// THIS IS NEW
if (this->browser_command_line_switches_.size() != 0) {
  executable_and_url.append(L" ");
  executable_and_url.append(this->browser_command_line_switches_);
}

executable_and_url.append(L" ");
executable_and_url.append(this->initial_browser_url_);

LOG(TRACE) << "IE starting command line is: '"
           << LOGWSTRING(executable_and_url) << "'.";

I also make sure that when adding arguments in python, I put the variables in double quotes.

ieOptions.add_argument('--user-data-dir="'+msedge_user_profile + '"')
ieOptions.add_argument('--profile-directory="Default"')

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
G-msedgedriver Requires fixes in MSEdgeDriver I-defect
Projects
None yet
Development

No branches or pull requests

3 participants