I’m setting up chromedriver (win32) on visual studio using C#, I have firefox and it works great. I have downloaded the chromedriver.exe and set the PATH in windows to its location (C:...misc...\Selenium Webdriver\chromedriver) as the book “selenium recepies in C sharp” suggests. I am able to open up the driver via cmd and see the port. I have also used the NuGet package manager to get the chromewebdriver there. I have looked at this link with no success.
Chrome open for a split second and then closes.
My code.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Chrome;
namespace UnitTestProject1
{
[TestClass]
public class BrowserTest
{
[TestMethod]
public void ChromeTest()
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://www.google.com");
}
}
}
I’m willing to remove everything and start from scratch if I’ve botched the install somewhere along the way. Any help would be great.
EDIT: I have uninstalled and reinstalled chrome also.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Chrome;
namespace UnitTestProject1
{
[TestClass]
public class BrowserTest
{
string DRIVER_PATH = #"C:...misc...\Selenium Webdriver\chromedriver";
[TestMethod]
public void ChromeTest()
{
IWebDriver driver = new ChromeDriver(DRIVER_PATH);
driver.Navigate().GoToUrl("http://www.google.com");
}
}
}
I am new to selenium. As per tutorial I installed Web Driver for Google Chrome i.e WebDriverChromedriver. On running the sample program I got the same issue.
Then I installed "Selenium.Chrome.WebDriver" package from Nugetpackage. And my program got executed successfully.
Related
I downloaded Mono from the oficial website, I added path using CMD: setx path "%path%;C:\Programs\Mono\bin" and then I opened Mono to see comands. I wrote a code using notepad to test it:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, world!");
Console.ReadLine();
}
}
}
I named it into mis.cs and now I want to debug it!
I wrote cd C:/Users... and than I tried first mono mis.cs but said that Cannot open assembly 'mis.cs': File does not contain a valid CIL image. And than I wrote mono --debug mis.cs and said the same. I tried also with 'mono --debug mis.cs -o mis.exe' and same.
What should I do? I don't want to use Microsoft VS. I want to use the old method.
Here is my code. I have use nuget package selenium, chrome drive and chrome drive exe.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace selenium
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://www.google.com");
driver.FindElement(By.Name("q")).SendKeys("test");
}
}
}
You need to enable logs and check them. Possible problem may be that browser cannot be started (e.g. Chrome and ChromeDriver are not installed/configured). Another possibility could be that outgoing internet traffic is blocked, what typically happens on servers in production.
I want to run firefox headless.
Not hide the browser window or open it in a virtual desktop, Firefox supports headless mode by using "-headless" flag.
Problem is I know how to do it in chrome but not in Firefox.
My code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace MyApp {
public partial class Form1: Form {
public Form1() {
InitializeComponent();
}
private void StartBtn_Click(object sender, EventArgs e) {
IWebDriver driver;
FirefoxOptions options = new FirefoxOptions();
options.AddArguments("--headless");
driver = new FirefoxDriver(options);
}
}
}
My WinForm application only has a button with name StartBtn.
On clicking of the button Firefox should run headless, but it opens in a normal window.
Update
I updated firefox to 56.0.1
Now I get a different error:
An unhandled exception of type 'OpenQA.Selenium.WebDriverException'
occurred in WebDriver.dll
Additional information: Expected browser binary location, but unable
to find binary in default location, no 'moz:firefoxOptions.binary'
capability provided, and no binary flag set on the command line
Headless mode in Firefox is supported from version 56 on Windows and Mac OS. Ensure that you have the correct version installed.
https://developer.mozilla.org/en-US/Firefox/Headless_mode#Browser_support
With Firefox v56.0.1, Selenium.WebDriver v3.6.0 and geckodriver v0.19.0 (x64) this works correctly for me.
Regarding the error:
An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll
Ensure you're using the correct version of geckodriver. I suspect you're using the x32 build on an x64 machine, get the x64 build.
https://github.com/mozilla/geckodriver/releases
I was always able to launch chromedriver server locally but then I tried to do this remotely and since then I am unable to launch it. I reinstalled chrome as well the chrome driver but nothing seems to fix this. Even when I give the path of my driver it won't launch.
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium.Safari;
using OpenQA.Selenium.Interactions;
namespace TestWebDriver
{
class Program
{
static void Main(string[] args)
{
var driver = new ChromeDriver(#"C:\Users\laurens.putseys\Documents\Visual Studio 2015\Projects\TestWebDriver\packages\Selenium.WebDriver.ChromeDriver.2.21.0.0\driver\");
driver.Url = "http://google.be";
Console.ReadLine();
driver.Quit();
}
}
}
The error I get is the following:
An unhandled exception of type 'System.InvalidOperationException' occurred in WebDriver.dll
Additional information: unknown error: chrome failed to start
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86_64)
It started after I tried this:
System.Environment.SetEnvironmentVariable("webdriver.chrome.driver",#"/path/to/where/you/ve/put/chromedriver.exe"
Now I cannot launch the local either. Launching IE and Firefox local work without any problems. Any ideas? Thanks in advance!
try downloading the driver and give its path to contractor - LINK
driver = new ChromeDriver(DRIVER_PATH);
By the version number (2.21.371459) you can tell that the ChromeDriver executable has been launched by your remote Selenium server. But the ChromeDriver was obviously unable to launch the Chrome browser. Is it installed on the server? Can you launch is manually? Can you watch the remote server on a screen and see what happens? Are there any error message boxes displayed by Chrome?
Maybe uninstalling and re-installing Chrome could help!
I had the same problem. I had the browser set to always run under the administrator.
So I started Visual Studio as an administrator and the problem was solved.
I wrote my first selenium script and it worked. here is the code below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace test1Sel
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver(#"C:\ChromeDriver");
If i try and write a new script however i get an error on the driver saying Invalid argument has been supplied. I am using Visual Studio 2013 Pro. I am not sure why the line worked the first time but will not work in any other script. i have installed both selenium packages in the first script and in any other test script i have tried. any ideas would be great!
Try to replace Chrome driver into the bin folder (solution\project\bin\debug), and use constructor without path (without arguments).
IWebDriver driver = new ChromeDriver();