Set Profile Chrome WebDriver Selenium VBA - vba

I'm trying to set a profile in chrome, but it does not work.
Chrome Version: Version 80.0.3987.106
WebDriver: ChromeDriver 80.0.3987.106
Selenium Basic: SeleniumBasic-2.0.9.0.exe
Option Explicit
Public Sub openGChrome()
Dim obj As New WebDriver
Dim i As Integer
Const URL = "https://www.linkedin.com/feed/"
Const JS_PROFILE As String = "C:\Users\ChuckNorris\AppData\Local\Google\Chrome\User Data\Default"
Set obj = New ChromeDriver
With obj
.SetProfile JS_PROFILE, True
.Get URL
Stop
.Quit
End With
End Sub
What i'm doing wrong? Any help?
Edit:
The browser open, but i dont have any profile select, i can't login to websites without signin

You did not specify what "does not work", but I think you should take away the \Default from your profile path, because when you don't specify the name of the profile, meaning you want to use the default one, the \Default is then added implicitly.
To specify a certain profile other than the default, you would want to use:
.AddArgument ("profile-directory=foldername") 'foldername is the name of the folder with the profile you want to use

Related

Selenium Webdriver and Embedded Browser in a Winform - How to connect web_driver instance?

I need to connect/create an instance of Selenium Webdriver to web content that my application under test opens in a Winform.
My test framework opens the Winform application with CodedUI, and further test steps cause the Winform application to open another Winform window that has a browser embedded in it. I need to create or tie a Selenium instance to this embedded browser content. It's using WebViewer/Edge in the embedded area.
Note - Not yet ready to move to WinAppDriver, if ever.
Resolved this. I found out that the web pane is an object called a WebView2.
Automating inside it requires the application to be launched in a special way:
Dim AppPath As String = "[full path to your app and its name].exe"
Dim edgeOptions As New EdgeOptions
edgeOptions.UseChromium = True
edgeOptions.UseWebView = True
edgeOptions.DebuggerAddress = "localhost:9222"
Dim AppStartInfo = New ProcessStartInfo(AppPath)
AppStartInfo.UseShellExecute = False
AppStartInfo.EnvironmentVariables("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS") = "--remote-debugging-port=9222"
Diagnostics.Process.Start(AppStartInfo)
You also need:
Selenium Support and Selenium Webdriver version 4.0.0-rc3 installed in the projects
msedgedriver from here: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
And finally in your automation code, when the window with WebView2 in it finally appears, you need to run this code to tie selenium webdriver to the WebView2 pane:
Dim driver As String = "[path to:]msedgedriver.exe"
Dim edgeOptions As New EdgeOptions
edgeOptions.UseChromium = True
edgeOptions.UseWebView = True
edgeOptions.DebuggerAddress = "localhost:9222"
Dim WebDriver = New EdgeDriver(EdgeDriverService.CreateDefaultService(".", driver), edgeOptions)

Using Selenium and VBA to navigate Chrome, but getting popup: Loading of unpacked extensions is disabled by the administrator

I am trying to use selenium to open Chrome, but I am getting an popup that I can't resolve. It seems a solution has been found using JAVA, but I can't easily find something for VBA. In case the image doesn't load, it says "Failed to load extension from: <>local location<>. Loading of unpacked extensions is disabled by the administrator."
The closest thing I have found is this line, but it doesn't seem to do anything.
.SetPreference "profile.default_content_setting_values.notifications", 2
Here is the full code:
Option Explicit
Public Sub Demo()
Dim d As WebDriver
Set d = New ChromeDriver
Const URL = "https://www.google.com/"
With d
.SetPreference "profile.default_content_setting_values.notifications", 2
.Start "Chrome"
.Get URL
.FindElementById("lst-ib").SendKeys "Selenium basic GitHub"
.FindElementsByTag("form")(1).FindElementByCss("input[value='Google Search']").Click
'.Quit
End With
End Sub

How to enable IE mode in Chromium Edge Browser in selenium C#?

I want to automate a website in Edge which is require IE mode to be enabled. How can launch Edge in IE mode in selenium?
Below code which I currently use launches Edge in non IE mode, which won't display the website properly.
Dim edgeDriverService = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService()
Dim edgeOptions = New Microsoft.Edge.SeleniumTools.EdgeOptions()
edgeOptions.PageLoadStrategy = PageLoadStrategy.Normal
edgeOptions.UseChromium = True
Dim driver As IWebDriver = New Microsoft.Edge.SeleniumTools.EdgeDriver(edgeDriverService, edgeOptions)
driver.Navigate().GoToUrl("http://example.com")
Tried using edgeOptions.AddAdditionalCapability("ie.edgechromium", True)but it didn't work
You could refer to the section Automating Internet Explorer mode in this article about how to use IE mode in Edge Chromium in Selenium C#.
You could refer to the following steps:
Download the latest version of IEDriverServer from Selenium site. Here I use 32 bit Windows IE version 3.150.1.
Make some preparations to use IEDriver according to this.
Create a C# console project using Visual Studio.
Install Selenium.WebDriver 3.141.0 nuget package from Nuget package manager.
Add the code below to the project and modify the paths to your owns in the code:
static void Main(string[] args)
{
var dir = "{FULL_PATH_TO_IEDRIVERSERVER}";
var driver = "IEDriverServer.exe";
if (!Directory.Exists(dir) || !File.Exists(Path.Combine(dir, driver)))
{
Console.WriteLine("Failed to find {0} in {1} folder.", dir, driver);
return;
}
var ieService = InternetExplorerDriverService.CreateDefaultService(dir, driver);
var ieOptions = new InternetExplorerOptions{};
ieOptions.AddAdditionalCapability("ie.edgechromium", true);
ieOptions.AddAdditionalCapability("ie.edgepath", "{FULL_PATH_TO_MSEDGE.EXE}");
var webdriver = new InternetExplorerDriver(ieService, ieOptions, TimeSpan.FromSeconds(30));
webdriver.Url = "http://www.example.com";
}
Run the project to test:
Notes:
Make sure to close all the Edge browser tabs and window before running the code.
Use full paths in the code. For example: ieOptions.AddAdditionalCapability("ie.edgepath", #"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe");.

Is there an Internet Explorer webdriver configuration for ignoring security certificates on serenity?

For context, I use a serenity.properties file for my webdriver configurations.
I am using serenity 2/cucumber 4/java.
I wanted to use something similar to how Chrome driver works with serenity properties.. Something like:
chrome.capabilities.acceptInsecureCerts = true
Which allows me to bypass that the security certificate error for Chrome Driver.
But I couldn't find something similar to this configuration for the serenity IE driver.
My question is: is there a way to do this via serenity.properties configurations similarly for IE driver, rather then having to declare and pass something like this?
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
System.setProperty("webdriver.ie.driver","IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver(capabilities);
source
Things I've tried while running on my selenium grid:
iexplorer.capabilities.acceptInsecureCerts = true
iexplorer.capabilities.acceptSslCerts = true
iexplorer.capabilities.introduceFlakinessByIgnoringSecurityDomains = true
iexplorer.capabilities.setJavascriptEnabled = true
Should iexplorer.capabilities even work?
Example of security certificate error on IE:
I have checked the selenium IE webdriver document and github forum, and search lots of resources about how to handle the SSL Certificate in Selenium IE WebDriver. It seems that we could only set the ACCEPT_SSL_CERTS property via the DesiredCapabilities method, and use the following code for IE Webdriver:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
System.setProperty("webdriver.ie.driver","IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver(capabilities);

Javascriptexecutor is not working while running through safari webdriver

I want to perform a click using javascriptexecutor.
JavasciptExecutor jse=(JavascriptExecutor) webDriver;
jse.executescript("arguments[0].click();",webelement)
While running from safari,it is showing "undefined is not a function<evaluating arguments[0].click "
Same works fine in chrome driver.
Am I need to add any capabilities while initiating webDriver?
I have already added capabilities.SetJavascriptEnabled(true). Still it is not working
You have to set the capabilities of driver browserwise.
When running the testcases in safari browser set a global flag for browser. You can create a config file and add "safari" or "chrome" when running it through safari or chrome.
In your source initialize your driver for safari like below :
if (browser.equals("safari")) {
SafariOptions safariOptions = new SafariOptions();
safariOptions.setUseCleanSession(true);
safariOptions.setUseTechnologyPreview(true);
driver = new SafariDriver(safariOptions);
}
Then navigate to your desired url. Here i am adding a sample source for your understanding.
driver.get("https://www.google.com");
WebElement elem = driver.findElement(By.className("gb_P"));
jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].click();", elem);
Hope this will solve your issue. Feel free to comment here for more information.