Selenium - start your normal chrome and not chromium - c#

im looking example how can i start my normal google chrome in webdriver c#?
For now i use :
ChromeDriver driver;
public ChromeDriverService chromeDriverService;
chromeDriverService = ChromeDriverService.CreateDefaultService();
chromeDriverService.HideCommandPromptWindow = true;
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("disable-infobars");
chromeOptions.AddExcludedArgument("enable-automation");
chromeOptions.AddAdditionalCapability("useAutomationExtension", false);
driver = new ChromeDriver(chromeDriverService,chromeOptions);
But it run my chromedriver.exe installed inside project. Can i just run my simple installed chrome? Without download any chromedriver.exe? It's important for me , because some website check if there is opened chromium with chromedriver.exe.
Is it possible to do that?

If you want not just open it but also perform some interaction with your site then you have to deal with Selenium and WebDriver.
You can try Python and undetected-chromedriver which has some workarounds preventing some systems to detect that your browser is running under webdriver control.

Unfortunately, it's the chromedriver.exe that lets you interact with Chrome so, without the driver, you wouldn't be able to interact with the actual browser.
If your issue is with chromium, try driving Mozilla with GeckoDriver

Selenium always uses chromedriver.exe for interacting with Chrome, I think you mean you want to load your default data directory. You can add a chrome option for this purpose:
chromeOptions.AddArguments(#"C:\Users\<your user name>\AppData\Local\Google\Chrome\User Data")
Take care, any other chrome must not be running that time with the same data directory. Like you may have run for your personal use.
You can also create a data directory somewhere else if you just want to show some realistic behavior to a website. But some websites are smart enough so it does not work every time.

Related

Use Selenium to attach to a manually opened Browser

I know, that such a question is already asked here before, but it is 4 years old and not quite helpful.
So, what i want to do is simple, i want my selenium (running in WPF and .Net 5.0 in c#) so connect to an open browser to control it. The browser is opened manually with the debuggingport 9222 and i can successfull connect to this browser from another browser instance.
i am able to open a NEW Chrome browser with selenium and control it, but i need to also have the ability to connect to an open instance.
and help would be awesome.
PS: i know that selenium is for testing, and normally not used to not be in a controlled test-environment. =)
thank you so much for you help guys.
Type : chrome://version/ in browser you will get executable path of chrome.exe
copy this and close all chrome instance.
**close all chrome instance and **
start chrome as:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --remote-debugging-port=5555
verify chrome is started with port open by going to localhost:5555
Now add remote debugging port as:
var options = new ChromeOptions();
options.debuggerAddress= "127.0.0.1:5555";
var driver = new ChromeDriver(options);
use chrromeoptions to connect to that port from selenium

(C#) How can I hide the Selenium Webdriver console application while also providing a custom path to the drivers?

I have a requirement to both hide the console that comes up when using Selenium-Webdriver and also being able to provide a custom path to the exact location and version of the driver I'm using. There doesn't appear to be a constructor that accepts both the string for the directory, and the DriverService for hiding the console. How can I accomplish both these tasks? I will eventually need to implement this for all browsers, so an example with any of them would be amazing.
I actually got lucky and figured it out. DriverService is able to take the driver path as an argument! Here's a chrome example:
ChromeDriverService service = ChromeDriverService.CreateDefaultService(driverPath);
service.HideCommandPromptWindow = true;
ChromeDriver chromeDriver = new ChromeDriver(service);

Geckodriver 0.16.0 start firefox with flashplayer

Since geckodriver v0.16.0 flashplayer is disabled by default.
Is there any possibility to start firefox with enabled flashplayer?
I'm using C#. My code right now:
var profileManager = new FirefoxProfileManager();
FirefoxProfile profile = profileManager.GetProfile("selenium"); //created firefox user named selenium
profile.SetPreference("plugin.state.flash", 1);
Code bellow doesn't work for me:
profile.SetPreference("dom.ipc.plugins.enabled.libflashplayer.so", true);
When I use this one:
profile.SetPreference("plugin.state.flash", 1);
firefox is asking if I want to enable flashplayer, and than refreshes page (with all inputs filled previously - so i got empty fields).
If I select "allow and remember", next time I start this code nothig is saved. I'm getting the same situation.
I found solution there:
How to enable Adobe Flash in FireFox Selenium webdriver with FirefoxProfile
If I replaced profile.setPreference("plugin.state.flash", 1); to profile.setPreference("plugin.state.flash", 2); it stopped to asking me if I want to enable flash player.
Here is the solution for you:
With Selenium 4.3.0, gecko driver v0.16.0 & Mozilla Firefox 53.0 this code works well with myfreecams.com.
It is worth mentioning that the default Firefox profile is not very automation friendly. When you want to run automation reliably on a Firefox browser it is advisable to make a separate profile. Automation profile should be light to load and have special proxy and other settings to run good test. You should be consistent with the profile you use on all development and test execution machines. If you used different profiles everywhere, the SSL certificates you accepted or the plug-ins you installed would be different and that would make the tests behave differently on the machines.
So, Create a New Firefox profile and use the same in the Test script involves three steps process. First you need to Start the Profile Manager, second is to Create a New Profile and third is to use the same profile in Test scripts. Let's assume we created a new FirefoxProfile by the name "debanjan".
Use the following code to open http://www.myfreecams.com/ with your new FirefoxProfile "debanjan":
String driverPath = "C:\\Utility\\BrowserDrivers\\";
//Mozila Firefox
System.setProperty("webdriver.gecko.driver", driverPath+"geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("debanjan");
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, testprofile);
FirefoxDriver driver = new FirefoxDriver(dc);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.navigate().to("http://www.myfreecams.com/");
PS: This code is in Java so you may have to convert it into C# format.
Let me know, if this helps you.

Selenium, how to take screenshot without opening the browser?

I want to take a screenshot of a webpage using Selenium.
I have notice that the action to take the screenshot require to open the web browser itself.
tried to change webDriver.Navigate().GoToUrl("http://www.google.com"); with webDriver.Url = "http://www.google.com"; but no success,
I even tried to leave it with no url and the browser opened with url of 'data', which now I understand that something else makes the browser to be open.
private void button1_Click(object sender, EventArgs e)
{
var capabilitiesInternet = new
OpenQA.Selenium.Remote.DesiredCapabilities();
capabilitiesInternet.
SetCapability("ignoreProtectedModeSettings", true);
IWebDriver webDriver = new ChromeDriver();
webDriver.Navigate().GoToUrl("http://www.google.com");
Screenshot screenshot = ((ITakesScreenshot)webDriver).GetScreenshot();
screenshot.SaveAsFile("E:\\ScreenShot.png",
System.Drawing.Imaging.ImageFormat.Png);
webDriver.Quit();
}
No - you need to let the WebDriver request the page, otherwise how can it know what screenshot to produce?
If you're trying to avoid a real, 'slow' browser starting up and opening a window, you should either consider running that browser headlessly, as per:
How do I run Selenium in Xvfb?
Or check out the headless WebKit browser PhantomJS (or maybe SlimerJS), and using almost exactly the same WebDriver API as you have now, ask it to produce your screenshots 'in-memory':
Phantomjs - take screenshot of a web page
Just replace:
WebDriver webDriver = new ChromeDriver();
with:
WebDriver webDriver = new PhantomJSDriver();
(Obviously requires the application to be installed locally)
Edit: Just a note that the typical use-case for this is 'overnight' continuous-integration / continuous-testing when run from headless CI servers. However, it can be very easily added to other work-flows, e.g. for visual regression-testing, and simple one-off checks.
There's multiple ways to go about it:
There is chrome flag --no-startup-window which should open chrome without window. I tried it, and it didn't work, however, you can give it a go.
Use hacks - there is a way to start chrome without you ever seeing it, it works nicely. Just use --window-position=-9999,0, note that, TakeScreenShot() has some weird anomalies in my experience - it focuses the window, it runs out of memory randomly, etc. What I ended up doing is I wrote chrome extension which can take screenshots and return them back to selenium through JS.

Selenium C# Webdriver IE11 issues

I am struggling through what appear to be issues with WebDriver properly interacting with the Internet Explorer Server (IE11). I have quite a number of tests already authored and working in Chrome but when I try to run the exact same tests using the latest IE Driver server (2.46.0 - downloaded from http://www.seleniumhq.org/download/)
I have read a number of articles on setting up a registry entries and adding my site to the list of trusted sites to to possibly handle a few of these issues but I have been un-successful (Selenium WebDriver on IE11)
Within the page above, one of the responses links to a Microsoft site for downloading IE Web Driver for IE 11 (http://www.microsoft.com/en-us/download/details.aspx?id=44069), this link wants to download and install something.
My question: Is there a difference in the WebDriver from the Selenium site versus the MS site?
Thanks
Sean
Try disabling the native event for IE shown as follows
var options = new InternetExplorerOptions { EnableNativeEvents = false };
options.AddAdditionalCapability("disable-popup-blocking", true);
Driver = new InternetExplorerDriver(options);
Also, DesireCapabilities expands the ability of controlling driver instance more.

Categories

Resources