This is the C# code I have. When I run it it starts in headless mode but it seems to have an issue with the Chrome extension.
[Test]
public async Task Start()
{
var chromeDriverService = ChromeDriverService.CreateDefaultService();
var option = new ChromeOptions();
option.AddExtension(MainPageElements.extensionPath);
option.AddArguments("headless");
using (var browser = new ChromeDriver(option))
{
WebDriver webDriver = new ChromeDriver(chromeDriverService, option);
webDriver.Manage().Window.Maximize();
//more code
}
}
This is the error I get when I run it:
OpenQA.Selenium.WebDriverException : unknown error: failed to wait for extension background page to load: chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.html
from unknown error: page could not be found: chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.html
The extension is MetaMask. It's a crypto wallet.
It could be not possible at all using headless mode when loading this Chrome extension since it opens a new pop up window of its own...
edit: Version of ChromeDriver - 108.0.5359.7100
You have to put
option.AddArguments("--headless=new")
just before the command option.AddExtension(MainPageElements.extensionPath);
source https://bugs.chromium.org/p/chromium/issues/detail?id=706008#c36
Related
I am trying to hide command prompt window when starting selenium chrome, but I can't figure it out.
Here is my code:
var driverService = ChromeDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("--headless");
var browser = new ChromeDriver(driverService, chromeOptions);
But it crash on: System.InvalidOperationException: 'session not created: This version of ChromeDriver only supports Chrome version 85
I tried to manually add path to driver but It crash's also.
Different code I used
var driverService = ChromeDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("--headless");
chromeOptions.BinaryLocation = "C:\\Users\\TriX\\Downloads\\chromedriver_win32";
var browser = new ChromeDriver(driverService, chromeOptions)
Now it crash on: OpenQA.Selenium.WebDriverException: 'unknown error: Failed to create Chrome process.'
Thanks for help I am completely lost :(
I tried different codes as shown, but without success.
Thanks to #r000bin i managed to resolve the problem. I also find out that I installed outdated version of ChromeDriver. So, I downloaded the correct one and it started to work.
I had old ChromeDrive nuget version
Downloaded the new one and uninstalled old one
Started to work :)
So I am starting to learn automation using Selenium and C#, problem is i can navigate to my facebook, google what ever and all works good on firefox. But when using IE browsers it opens the webpage but then throws error 'NoSuchElementException'. I am using same code, one works one does not.
here is IE code
IWebDriver driver = new InternetExplorerDriver(#"C:\folder");
driver.Navigate().GoToUrl("http://www.google.com");
driver.FindElement(By.Name("q")).SendKeys("Hello World");
Here is firefox code
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.google.com");
driver.FindElement(By.Name("q")).SendKeys("Hello World");
This could be timing issue on both browser. You should try using more stable code using WebDriverWait to wait until element is visible before interaction as below :-
IWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(By.Name("q")));
element.SendKeys("Hello World");
I have a Selenium suite which has 150 test cases. The test has to run in Incognito mode in Chrome Browser.
I am able to launch the browser in incognito Mode. But the issue is the browser is not getting maximized ( say for 10 test cases and for remaining 140 test cases the browser launches in maximized mode) , though there is a code to maximize the browser.
As a result of this, some of the test fails ( All 10 test ).
Below is my code
desiredCapabilities = DesiredCapabilities.Chrome();
var options = new ChromeOptions();
options.AddArgument(#"--incognito");
options.AddArgument("--start-maximized");
desiredCapabilities.SetCapability(ChromeOptions.Capability, options);
webDriver = new MyWebDriver(new Uri(gridHubURL), options.ToCapabilities(),TimeSpan.FromSeconds(ApplicationConfiguration.RemoteDriverTimeOutValue),testContext);
break;
Is there a way to ensure that the browser always (100%) launches in maximised mode.
The click operation fails when the browser is not maximised.
System.InvalidOperationException: unknown error: Element is not clickable at point (886, 466). Other element would receive the click:
For this reason, I want to run in maximised mode. In maximised mode, I am not getting this error. Please help .
Thanks
Try this code:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--incognito");
IWebDriver driver = new ChromeDriver("C://",options);
It works for me
Could do something like this:
desiredCapabilities = DesiredCapabilities.Chrome();
var options = new ChromeOptions();
options.AddArgument(#"--incognito");
options.AddArgument("--start-maximized");
desiredCapabilities.SetCapability(ChromeOptions.Capability, options);
webDriver = new MyWebDriver(new Uri(gridHubURL), options.ToCapabilities(),TimeSpan.FromSeconds(ApplicationConfiguration.RemoteDriverTimeOutValue),testContext);
webDriver.Manage().Window.Maximize();
break;
It will need to be after the webDriver opens up, but it will maximize the window for you.
Try this instead, I have tested and should be fine
var caps = DesiredCapabilities.Chrome();
var options = new ChromeOptions();
options.AddArgument(#"--incognito");
options.AddArgument(#"--start-maximized");
caps.SetCapability(ChromeOptions.Capability, options);
var webdriver = new ChromeDriver(options);
webdriver.Navigate().GoToUrl("http://yourURL.com");
webdriver.Manage().Window.Maximize();
An alternative would be to set the initial size:
options.AddArgument("--window-size=1024,768");
You could also set some extreme values. The window should then have the size of the screen since the OS limits it (at least on Windows) :
options.AddArgument("--window-size=32000,32000");
I try to load ChromeDriver with adblock, and somehow it reloads downloading the extension everytime it runs and shows this message:
If you see this message every time you start AdBlock, please make sure you are not using a file cleaner that also cleans 'localStorage' files.
var options = new ChromeOptions();
options.AddArgument("--no-experiments");
options.AddArgument("--disable-translate");
options.AddArgument("--disable-plugins");
options.AddArgument("--no-default-browser-check");
options.AddArgument("--clear-token-service");
options.AddArgument("--disable-default-apps");
options.AddArgument("--no-displaying-insecure-content");
options.AddArgument("--disable-bundled-ppapi-flash");
options.AddExtension(#"D:\AdBlock-v2.6.5\adblock.crx");
using (IWebDriver driver = new ChromeDriver(options))
{
driver.Navigate().GoToUrl(url);
}
Try to use the same chrome profile on every run. This must resolve the issue.
Code to do this located here: Load Chrome Profile using Selenium WebDriver
I created a console application (with target: .Net Framework 4) and added the next references:
Selenium.WebDriverBackedSelenium.dll
ThoughtWorks.Selenium.Core.dll
WebDriver.dll
WebDriver.Support.dll
static IWebDriver driver = null;
if (driver == null)
{
ChromeOptions options = new ChromeOptions();
options.AddArguments("--start-maximized");
driver = new ChromeDriver(#"C:\selenium\net40", options);
// it opened a new window (about:blank)
}
driver.Navigate().GoToUrl("http://www.facebook.com");
but nothing is happen.
I use: ChromeDriver 26.0.1383.0
and my chrome browser version is: 29.0.1547.62 m
this is the command line:
Started ChromeDriver
port=1866
version=26.0.1383.0
log=C:\Users\salon\Desktop\Application Alon\ConsoleApplication1\ConsoleApplicati
on1\bin\Debug\chromedriver.log
[156:4144:0828/233852:ERROR:platform_thread_win.cc(127)] NOT IMPLEMENTED
[5804:5712:0828/233856:ERROR:textfield.h(173)] NOT IMPLEMENTED
I have windows 7 if it's needed..
any help appreciated!
For the later versions of Chrome (27+), there is a new shiny ChromeDriver:
http://code.google.com/p/chromedriver/downloads/list
Note the section within the summary on the page...
ChromeDriver server for win32 (v2.2.215849.dyu) supports Chrome v27-30
Also, you should remove the Thoughtworks & WebDriverBackedSelenium references, they are not required and you don't seem to be using them.