问题
I'm try to use selenium-server-standalone-2.33.0.jar with opera and need to change some profile preferences. It possible to create OperaProfile object in C# project and using it like this:
OperaProfile profile = new OperaProfile(); // Error: Type or namespace 'OperaProfile' could not be found
profile.preferences().set("User Prefs", "Ignore Unrequested Popups", false);
DesiredCapabilities capabilities = DesiredCapabilities.Opera();
capabilities.SetCapability("opera.profile", profile);
IWebDriver driver = new RemoteWebDriver(new Uri("http://host:4444/wd/hub"), capabilities);
In this case I got error message
Type or namespace 'OperaProfile' could not be found
回答1:
Assuming you are on Windows:
The Operadriver is written in Java and not suported directly in C#, as it is mainatined not by the Selenium project team but by Opera.
To use it, you have to run the standalone Selenium webserver (from console on windows) before starting the test. get it here
you need to set the OPERA_PATH to point to your opera.exe file. Start the server with the command:
java -jar selenium-server-standalone-2.33.0.jar
i use a small bat for these two tasks:
SET OPERA_PATH="C:\Progra~2\Opera\opera.exe"
cd C:\pathToSeleniumJarFile
C:\Progra~2\Java\jre7\bin\java.exe -jar selenium-server-standalone-2.33.0.jar
C#: testing with remotewebdriver object in your C# code to connect to it.
switch (WebBrowser)
{
case Browser.Chrome:
// chromedriver.exe has to be in the debug folder
ChromeOptions chrome = new ChromeOptions();
chrome.AddArguments("--ignore-certificate-errors");
webDriver = new ChromeDriver(chrome);
break;
...
case Browser.Opera:
//note: set OPERA_PATH environment variable (in cmd or global)
DesiredCapabilities opera = DesiredCapabilities.Opera();
opera.SetCapability("opera.profile", @"C:\OperaProfile");
webDriver = new RemoteWebDriver(opera);
break;
default:
throw new NotImplementedException();
if you want to manipulate the profile of the opera client (e.g. to accept untrusted certificates etc) you need to set
opera.SetCapability("opera.profile", @"C:\OperaProfile");
Copy an existing Profile to a location of your choice, here C:\OperaProfile.
==> Avoid spaces in all the pathes <==
来源:https://stackoverflow.com/questions/17009695/operaprofile-object-and-selenium-rc-c