I am trying to connect to profile, its successfully connect to custom firefox profile, but the problem after that is command FirefoxDriver driver = new FirefoxDriver(options); no more works, works only if i remove options then no custom profile.
the before last line returns error OpenQA.Selenium.WebDriverException: 'Process unexpectedly closed with status 0' or The HTTP request to the remote WebDriver timed out after 60 seconds, it only works if I remove options inside FirefoxDriver: FirefoxDriver driver = new FirefoxDriver(options);
Also, doing options.AddArgument("-profile" + "C:\Users\Chill\AppData\Roaming\Mozilla\Firefox\Profiles\5k2mdm2k.myprofile"); instead of spliting the 2 arguments does not launch firefox in the right profile.
Or even options.AddArgument("no-sandbox") or options.AddArgument("-no-sandbox") or options.AddArgument("--no-sandbox") doesn't works, also --profile instead of -profile does not open the right profile also, here is my code anyway:
using System;
using OpenQA.Selenium; // nuget package name: Selenium.WebDriver
using OpenQA.Selenium.Firefox; // nuget package name: Selenium.WebDriver.GeckoDriver
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
FirefoxOptions options = new FirefoxOptions();
options.AddArgument("-profile");
options.AddArgument(#"C:\Users\Chill\AppData\Roaming\Mozilla\Firefox\Profiles\5k2mdm2k.myprofile"); /* type about:profiles in firefox bar to create and manage firefox profiles, from there you will see which profile used, make sure to not use the default one and use root directory */
FirefoxDriver driver = new FirefoxDriver(options); /* code stops here and puts error after closing browser or waiting until it close itself after 60 sec */
driver.Navigate().GoToUrl("https://www.google.com/"); /* can only reach this part of code if i remove turn FirefoxDriver(options); to FirefoxDriver(); on the line upper, but no more custom profile so */
}
}
}
Hope you can help im blocked on this step for 3 days
Using these nugget versions:
<PackageReference Include="Selenium.Firefox.WebDriver" Version="0.27.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.0.0-beta4" />
This works for me:
using OpenQA.Selenium.Firefox;
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var options = new FirefoxOptions();
var profile = new FirefoxProfile(#"C:\Users\CatalinR\AppData\Roaming\Mozilla\Firefox\Profiles\f9n067l1.default");
options.Profile = profile;
var driver = new FirefoxDriver(options);
driver.Navigate().GoToUrl("https://www.google.com/");
}
}
}
Related
Greetings stackoverflow community,
I am trying to compile and run the programcode from this website:
https://social.msdn.microsoft.com/Forums/en-US/7bdafd2a-be91-4f4f-a33d-6bea2f889e09/c-sample-for-automating-ms-edge-chromium-browser-using-edge-web-driver
I followed all the instructions listed in the link and set my paths were I wanted them.
The program and the edge driver starts running, but then an error appears.
"An error exeption "System.InvalidOperationException" appeared in WebDriver.dll.
Further Inforamtion: session not created: No matching capabilities found (SessionNotCreated)"
This is the code from my program, more or less copied from the link above:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var anaheimService = ChromeDriverService.CreateDefaultService(#"C:\edgedriver_win64", "msedgedriver.exe");
// user need to pass the driver path here....
var anaheimOptions = new ChromeOptions
{
// user need to pass the location of new edge app here....
BinaryLocation = #"
C: \Program Files(x86)\Microsoft\Edge\Application\msedge.exe "
};
IWebDriver driver = new ChromeDriver(anaheimService, anaheimOptions); -- error appears at this line
driver.Navigate().GoToUrl("https: //google.com/");
Console.WriteLine(driver.Title.ToString());
driver.Close();
}
}
}
I would really appreciate your help!
Best Regards
Max
The article you refer to is a bit out of date. Now we don't need to use ChromeDriver to automate Edge. You can refer to the official doc about how to use WebDriver to automate Microsoft Edge.
I recommend using Selenium 4. Here I install Selenium 4.1.0 NuGet package and the sample C# code is like below:
using System;
using OpenQA.Selenium.Edge;
namespace WebDriverTest
{
class Program
{
static void Main(string[] args)
{
var options = new EdgeOptions();
options.BinaryLocation = #"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
var driver = new EdgeDriver(#"C:\edgedriver_win64", options);
driver.Navigate().GoToUrl("https://www.google.com");
Console.WriteLine(driver.Title.ToString());
driver.Close();
}
}
}
I want to open IE in Private mode to run the set of test cases. The browser is not opening. It shows error as
The HTTP request to the remote WebDriver server for URL {URL} timed out after 60 seconds
Sample code:
InternetExplorerOptions options = new InternetExplorerOptions()
{
ForceCreateProcessApi = true,
BrowserCommandLineArguments = "-private",
};
IWebDriver driver = new InternetExplorerDriver("C:\\Reports", options);
driver.Navigate().GoToUrl("https://www.google.com");
Also I have changed the TabProcGrowth as 0 in Registry Editor.
How to open IE in private mode to run the test case? Anything I want to update in my code. Thanks in advance.
This is how I manage to launch it:
Set the TabProcGrowth as 0 in Registry Editor.
Get the Selenium.WebDriver.IEDriver64 nugget instead of the normal 32 and build the project
Get the IEDriverServer64.exe from bin\Debug\netcoreapp3.1 (the output folder where this file is generated depends on your TargetFramework: .netcore or .netstandard)
Rename that file into IEDriverServer.exe and put it somewhere in a folder
Create the driver instance using the path to that folder. In my case, I created a folder in the project and pointed there
Project: Solution Explorer View
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using System.IO;
namespace InternetExplorerPrivate
{
public class Tests
{
public IWebDriver driver;
[SetUp]
public void Setup()
{
InternetExplorerOptions options = new InternetExplorerOptions();
options.ForceCreateProcessApi = true;
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
options.BrowserCommandLineArguments = "-private";
driver = new InternetExplorerDriver(Path.GetFullPath(#"..\..\..\IEDriver"), options);
}
[Test]
public void Test1()
{
driver.Navigate().GoToUrl("https://stackoverflow.com/");
}
}
}
I am trying to record the log files in Firefox using Selenium in c#;
I have put together a very simple example to try and open a browser and get the logs.
However this is throwing a 'Object reference not set to an instance of an object' exception on the following line.
var entries = driver.Manage().Logs.GetLog(LogType.Browser);
Can anyone help as to why this is happening and if there is any solution?
Here is the full code
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
FirefoxOptions options = new FirefoxOptions();
options.SetLoggingPreference(LogType.Browser, LogLevel.All);
var driver = new FirefoxDriver(options);
driver.Navigate().GoToUrl("http://stackoverflow.com");
var entries = driver.Manage().Logs.GetLog(LogType.Browser);
foreach (var entry in entries)
{
Console.WriteLine(entry.ToString());
}
Console.ReadLine();
}
}
}
I believe that this is an unsupported feature, here's the referenced issues:
https://github.com/SeleniumHQ/selenium/issues/1161
https://github.com/mozilla/geckodriver/issues/284
I am a beginner in Selenium WebDriver, and I have a problem with poping out notification on Facebook page while I'm trying to log in. I searched a lot, but i did not find anyhing usefull. I found code in java, convert into C# but it didn't work.(I hope that a did it properly) I tried something like this, but nothing. Please, help with this if you can.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, object> hash = new Dictionary<string, object>();
hash.Add("profile.default_content_setting_values.notifications", 2);
ChromeOptions op = new ChromeOptions();
op.AddAdditionalCapability("hash",hash);
IWebDriver driver = new ChromeDriver("path to googlewebdriver");
driver.Url = "http://facebook.com";
driver.Manage().Window.Maximize();
driver.FindElement(By.Id("email")).SendKeys("my email");
driver.FindElement(By.Id("pass")).SendKeys("mypassw" + Keys.Enter);
driver.FindElement(By.XPath("//*[#id='content_container']")).Click();
}
}
}
If you simply want to disable "all" notification on chrome browser, you can use switch --disable-notifications
Code in C# to launch chrome with this switch:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--disable-extensions"); // to disable extension
options.AddArguments("--disable-notifications"); // to disable notification
options.AddArguments("--disable-application-cache"); // to disable cache
driver = new ChromeDriver(options);
Here's list of switches available for chrome browser: Chromium Comamnd Line Switches
Alternatively, you have options to handle alert by using this code statement:
options.UnhandledPromptBehavior = UnhandledPromptBehavior.Dismiss;
You have other options available here to accept, dismiss, ignore etc.
To disable the annoying "some-annoying-website wants to: 🔔 Show notifications", set your ChromeOptions like this:
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("profile.default_content_setting_values.notifications", 2);
And pass it to your ChromeDriver:
using (var chrome = new ChromeDriver(options)) ...
ChromeOptions op = new ChromeOptions();
op.AddArguments("--disable-notifications");
Most importantly need to check the versions of Chrome Driver. Some versions it may not support.
I'm in a middle of process of creating utility console app to help me register to certain classes at my university. So far I've made it download website's content and frequently check for specific changes which gives me an information when the given course is full or available to be taken. Like that:
WebRequest request2 = WebRequest.Create("https://usosweb.umk.pl/kontroler.php?_action=katalog2/przedmioty/pokazPrzedmiot&prz_kod=0600-OG-ChH");
request2.Method = "GET";
WebResponse response2 = request2.GetResponse();
Stream stream2 = response2.GetResponseStream();
StreamReader reader2 = new StreamReader(stream2);
string content_2 = reader2.ReadToEnd();
string drugi = getBetween(content_2, #"Stan zapełnienia grup:</b>
<b>", "</b> (zarejestrowanych/limit)");
reader2.Close();
response2.Close();
if (drugi != pierwszy)
{
Console.WriteLine("Rejestracja!");
Console.Beep(3200, 900);
System.Diagnostics.Process.Start("https://usosweb.umk.pl/kontroler.php?_action=katalog2/przedmioty/pokazPrzedmiot&prz_kod=0600-OG-ChH");
pierwszy = drugi;
}
The problem is that it still requires my full attention, as I made it only open the website with the registration buttton on and my goal is to make it actually click it automatically after the slot opens.
Few things to note:
I have to be logged on that website in order to be able to register at the course
http://i.imgur.com/DtBCG3Q.jpg <- this is how that button is coded. The chain_ function is named differently with every single refresh
http://i.imgur.com/tGX5kmy.jpg <- that is how the registration panel looks like. Ideally I want a website to open in a default browser (or somewhere with cache so I am already logged in) and automatically press that button, as it doesn't require additional confirmation.
links to one of websites at my university are included in the code above so you may have an additional look on how the buton is coded and how that case could be solved.
After all, is that even possible? Am I able to code it through? I'm using C# but some additional snippets of codes in other languagues could be put it, if that will make it easier or possible.
I think that for this kind of task automation Selenium WebDriver is the best tool
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Chrome;
namespace WEBDRIVER
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://www.google.com/");
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("banana");
query.Submit();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until((d) => { return d.Title.ToLower().StartsWith("banana"); });
System.Console.WriteLine("Page title is: " + driver.Title);
driver.Quit();
}
}
}