Reputation: 438
I am using multiple profiles and hence want to give each a unique name so I can identify them quickly. So is there any way to launch a browser with a custom Profile name?
here is how I am launching the browser now.
new DriverManager().SetUpDriver(new EdgeConfig());
EdgeOptions options = new EdgeOptions();
options.AddArguments("--disable-gpu");
options.AddArguments("--disable-notifications");
options.AddArguments("enable-strict-powerful-feature-restrictions");
options.AddArguments("disable-geolocation");
options.AddArguments("--start-maximized");
options.AddArgument(@$"user-data-dir=MyDataDirectoryPath");
options.AddArgument(@$"profile-directory=MyProfileDirectory");
options.SetLoggingPreference(LogType.Driver, LogLevel.All);
var driverService = EdgeDriverService.CreateDefaultService(applicattionSettings.Settings.EdgeDriverPath);
driverService.HideCommandPromptWindow = true;
Driver = new EdgeDriver(driverService, options);
When I launch the browser from the above code default profile name is Profile 1, Profile 2, etc, and I want to change it.
Note: for the chrome browser, I have written a code to navigate to chrome://settings/manageProfile
find the input field on the page, and change the name and it's working fine.
here is the code.
driver.SwitchTo().NewWindow(WindowType.Tab);
DelayHelper.ActionDelayInSec(1, 1, cancellationToken);
driver.Navigate().GoToUrl("chrome://settings/manageProfile");
IWebElement inputField = (WebElement)driver.ExecuteScript("return document.querySelector('settings-ui').shadowRoot.querySelector('settings-main').shadowRoot.querySelector('settings-basic-page').shadowRoot.querySelector('settings-section > settings-people-page').shadowRoot.querySelector('settings-animated-pages').querySelector('settings-subpage').querySelector('settings-manage-profile').shadowRoot.querySelector('cr-input').shadowRoot.getElementById('input')"); ;
inputField.Clear();
inputField.SendKeys(email);
inputField.SendKeys(Keys.Enter);
I want to achieve the same for Edge browser but the problem is Edge browser does not have an input field directly on the page, I have to click the Context menu then click the edit icon and the popup with the input field opened, I tried to do that, but I think it's not possible to click context menu. so I want to know if is there any option to pass when launching the browser that helps change the browser name.?
Any help would be appreciated, Thank you.
Upvotes: 0
Views: 159
Reputation: 3106
First of all, there's been no such option to specify your custom profile names yet.
Actually, the context menu can be interacted with via keyboard input. Here're some ideas on how to get into that "Edit" menu after "More actions" (···) has been clicked:
Enter
key presses.These are all tested in the normal Microsoft Edge instances. Ideally, their relevant automation code should be:
Double Enter
key presses.
driver.Url = "edge://settings/profiles";
IWebElement clickable = driver.FindElement(By.Id("currentProfileOverflowButton"));
new Actions(driver)
.Click(clickable)
.SendKeys(Keys.Enter)
.SendKeys(Keys.Enter)
.Perform();
A single "e" press.
driver.Url = "edge://settings/profiles";
IWebElement clickable = driver.FindElement(By.Id("currentProfileOverflowButton"));
new Actions(driver)
.Click(clickable)
.SendKeys("e")
.Perform();
You can have a try and see whether it works for you.
UPDATE
After an investigation, I've found out that it is not possible to interact with the flyout menu after you click the More actions (···) with the webdriver because it is even not recognizable. I'll give you an example to show you why.
driver.Url = "edge://settings/profiles";
IWebElement clickable = driver.FindElement(By.Id("currentProfileOverflowButton"));
new Actions(driver)
.Pause(TimeSpan.FromSeconds(1))
.Click(clickable)
.Pause(TimeSpan.FromSeconds(1))
.SendKeys(Keys.Tab)
.Perform();
This example simulates the user clicks the More actions (···) and then presses TAB
. If we directly do this in Edge, you'll notice that TAB
does not work at all because now the focus is on the flyout menu (but it also does not work in the flyout menu unfortunately).
But if we let the webdriver do the same thing, you'll notice that after the flyout menu is called, TAB
works and switches focus to another option in the settings. It can well demonstrate that the webdriver fails to recognize the flyout menu. That's why we stuck at selecting "Edit".
Now, you can choose to create these profiles with customized names first, and then specify the profile path in each automation project. Or you can send feedback to Selenium Team to request a native API editing profile names. You may go to GitHub Selenium Issues to seek such support.
Upvotes: 0