I just started playing around with Selenium and Chromedriver, and cannot figure out how to launch it without Selenium's Chrome automation extension. This is required because due to the company policy here Chrome cannot handle unpacked extensions and my test app gives me an exception due to that.
I'm trying with
ChromeOptions options = new ChromeOptions();
options.AddArguments("disable-extensions");
IWebDriver driver = new ChromeDriver(options);
however it fails as I have read the whole code cannot be under
public partial class Form1 : Form
and I would have to put part of it inside a method. I can do that, but if I put
IWebDriver driver = new ChromeDriver(options);
inside anywhere that isn't directly inside my Form1 class it then the references I have under various click events fail to see the 'driver' object I defined there.
I searched around a lot but can't figure out how to structure the code so that it can properly read the option arguments AND also create the driver object in a way that other references can find. I'd really appreciate full examples as the other related topics didn't answer it for me.
Thank you
UPDATE:
Problem is I cannot get as far to compile the code, this is all due to the requirement to start ChromeDriver with a parameter. Without the parameter it all works, but I need it unfortunately, but I'm lost at how shjould I structure the code in a way that the object is not created directly inside the class yet click events can refer to it.
--
If I try to create the object under the Form1 class, I cannot pass the parameters to it, without those it works perfect. I have read it that if I want to add parameters to ChromeDriver it cannot be simply declared under the class.
If I put in under Form1_Load event for example, it can understand the parameters and opens the browser window with those parameters, but then my click events for various buttons cannot see the ChromeDriver driver I created under Form1_load, I get "xxx does not exist in the current context".
Also tried putting it all inside a
public ChromeDriver mymethod()
method, which has
return driver;
as it's return value. In this case, I can call that method in my button click events, but since the new ChromeBrowser obkect is defined in that method, each time i click the button to do something it creates a new browser windows as the code to create the object runs again. Tried to put an IF inside the method but it fails as I cannot
return driver;
on the ELSE chain without creating a new ChromeBrowser object in that chain as well, which results in yet another windows opened.
If there is any interest I can provide the code to look at.