FirefoxDriver Cannot start the driver service - selenium-webdriver

Have an app that has been running without issue (or so Ive been told) for months, but as of a few weeks ago started failing. Looking at the logs, I see a lot of these errors
EXCEPTION: Error intializing Firefox driver. Error message: 'Cannot
start the driver service on http://localhost:52022/';
WebDriverException stack: 'OpenQA.Selenium.WebDriverException: Cannot
start the driver service on http://localhost:52022/ at
OpenQA.Selenium.DriverService.Start() at
OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command
commandToExecute) at
OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String
driverCommandToExecute, Dictionary`2 parameters) at
OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities
desiredCapabilities) at
OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor
commandExecutor, ICapabilities desiredCapabilities) at ... ... .
The project is a console app that is using the Selenium project to try to connect to an external website but it seems it is having trouble just starting up. The code where this exception is caught is below.
this._logger = logger;
this._processLog = new List<string>();
FirefoxProfile profile = null;
FirefoxOptions options = null;
profile = new FirefoxProfile();
profile.SetPreference("browser.download.folderList", 2);
profile.SetPreference("browser.download.dir", downloadPath);
profile.SetPreference("browser.download.manager.alertOnEXEOpen", false);
profile.SetPreference("browser.download.manager.focusWhenStarting", false);
profile.SetPreference("browser.download.manager.closeWhenDone", true);
profile.SetPreference("browser.download.manager.showAlertOnComplete", false);
profile.SetPreference("browser.helperApps.alwaysAsk.force", false);
profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/json,text/csv");
profile.SetPreference("browser.download.manager.useWindow", false);
profile.SetPreference("browser.download.panel.shown", false);
options = new FirefoxOptions();
options.AddArguments("-headless");
options.AddArgument("no-sandbox");
options.Profile = profile;
try
{
this._driver = new FirefoxDriver(driverPath, options, TimeSpan.FromSeconds(180));
}
catch (WebDriverException ex)
{
string message = string.Format("Error intializing Firefox driver. Error message: '{0}'; WebDriverException stack: '{1}' ",
ex.Message, ex.ToString());
result.ProcessLog.Add(new LogMessage(LogLevel.EXCEPTION, message));
throw ex;
}
catch(Exception ex)
{
string message = string.Format("Error intializing Firefox driver. Error message: '{0}'; Exception stack: '{1}' ",
ex.Message, ex.ToString());
result.ProcessLog.Add(new LogMessage(LogLevel.EXCEPTION, message));
throw ex;
}
The computer where this process runs has the latest version of Firefox installed, however, the FireFox Selenium driver looks dated. Could there be a dependency issue?

Related

selenium c# edge browser : 'Unexpected error. Unknown error'

OS Build Number:- 18363.900
Edge Version: 83.0.478.54
MicrosoftWebDriver Version: 83.0.478.54
Here is the code:
System.Environment.SetEnvironmentVariable("webdriver.edge.driver", "E:\\edgedriver_win64\\msedgedriver.exe");
IWebDriver driver = new EdgeDriver();
I am getting error as: OpenQA.Selenium.WebDriverException: 'Unexpected error. Unknown error'
Which version of Selenium WebDriver are you using? I suggest you to use the latest version 4.0.0-alpha05 and use the code below:
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.UseChromium = true;
edgeOptions.BinaryLocation = #"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
var msedgedriverDir = #"D:\webdriver83.0.478.54";
var driver = new EdgeDriver(msedgedriverDir, edgeOptions);
driver.Navigate().GoToUrl("https://bing.com");
Thread.Sleep(3000);
driver.Close();
Note: Change the paths in the code to your owns.
Result:

Selenium Webdriver runtime Exception: unexpected alert "Please close other open tabs of the application and re-open this activity"

Selenium Webdriver runtime Exception: unexpected alert "Please close other open tabs of the application and re-open this activity", even though there are no other tabs open.
The Automation scripts were working fine, but recently I am getting the above exception.The Screenshot of the Alert:
I tried with different versions of chrome, selenium stand alone driver, but the issue still exist. Why is this alert coming, even though the application is not open in any of the tabs or browsers other than the one execution through online?
If this pop up is coming at some specific location every time then you can simply accept it by writing below lines :
WebDriver wb=new ChromeDriver();
wb.switchTo().alert().accept();
Else if any unexpected pop up is coming ,while initializing the driver then you can use the below code :
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
String path=new GetBasePath().getPath_XML()+dir;
prefs.put("download.default_directory", path);
options.addArguments("disable-extensions");
prefs.put("credentials_enable_service", false);
prefs.put("password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
options.addArguments("chrome.switches","--disable-extensions");
options.addArguments("--test-type");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
System.setProperty("webdriver.chrome.driver",**path to chromedriver.exe**"));
WebDriver wb= new ChromeDriver(cap);
My personal opinion , use both.

Exception in thread "main" java.lang.Error:Unresolved compilation problems: working with selenium

I am a begineer in selenium and trying my own after installation of eclipse, java, selenium, TestNg and started writing the below code.
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type
FirefoxDriver cannot be resolved to a type
at Mypackage.MyClass.main(MyClass.java:8)
package Mypackage;
public class MyClass {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://google.com";
String expectedTitle = "Welcome: Hello";
String actualTitle = "";
driver.get(baseUrl);
actualTitle = driver.getTitle();
if (actualTitle.contentEquals(expectedTitle)) {
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
driver.close();
}
}
you need to add selenium webdriver jar files to the project
right click on project-->goto build path-->configure build path-->click on "Add external jars"-->add selenium jar files from your local machine-->click ok-->now mouseover on WebDriver in your code-->click "import webdriver"--now run your code-->you will get rid of the exception.

Safari browser not launch on real device using appium

I was trying to launch safari browser on real device(iPhone 4) using appium. but it is giving following error.
Unable to install [/var/folders/7_/fz8kyhyn2g97s1m9zylk50xc0000gq/T/11545-10782-1dp1wfm/submodules/SafariLauncher/build/Release-iphoneos/SafariLauncher.app] to device with id [fdaxxx76].
Error [Error: Command failed: /bin/sh -c /Applications/Appium.app/Contents/Resources/node_modules/appium/build/fruitstrap/fruitstrap install --id fda51be7184f865f02de4f4c6cb8fff760964e76 --bundle "/var/folders/7_/fz8kyhyn2g97s1m9zylk50xc0000gq/T/11545-10782-1dp1wfm/submodules/SafariLauncher/build/Release-iphoneos/SafariLauncher.app"
Below is my sample code:
DesiredCapabilities cap = new DesiredCapabilities();
private static WebDriver driver;
#BeforeTest
public void prep() throws MalformedURLException {
System.out.println("Script started");
cap.setCapability("platformName", "iOS");
cap.setCapability("platformVersion", "8.3");
cap.setCapability("deviceName", "iPhone4");
cap.setCapability("udid", "fda51be7184f865f02de4f4c6cb8fff760964e76");
cap.setCapability("browserName", "Safari");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
}
#Test
public void googleTest() {
System.out.println("main method");
driver.get("http://google.com");
}
You need to create a provisioning profile to deploy it to a real device.
Follow instructions here.
Hope this helps,
Liam

GAE and HtmlUnit 2.9 - getting exception upon jsxGet_cookie

I'm trying to login to google using HtmlUnit in an app in GAE.
However, I keep getting this error:
Exception invoking jsxGet_cookie
Which is because
Caused by: java.lang.IllegalArgumentException: Invalid port: -1
at org.apache.http.cookie.CookieOrigin.<init>(CookieOrigin.java:58)
at com.gargoylesoftware.htmlunit.CookieManager.getCookies(CookieManager.java:127)
at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument.jsxGet_cookie(HTMLDocument.java:638)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:172)
... 94 more
This occurs when running in GAE and in my computer.
Has anybody ever seen this kind of error before?
How can I change the default Port?
Are there any workarounds?
Change the URL you are fetching to include the default port 80. Example: http://www.cnn.com becomes http://www.cnn.com:80. There's also a workaround involving overriding classes but I prefer to clarify the URL.
I had that problem at first (I have a GWT+GAE app) and I was using this very simple code and I got the js cookie exception and the port:-1 exception
WebClient webClient = Holder.get();
HtmlPage page=null;
try {
page = webClient.getPage(url);
System.out.println("CRAWLER DONE");
} catch (FailingHttpStatusCodeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// appengine hack because it's single threaded
String pageContent = page.asXml();
webClient.closeAllWindows();
return pageContent;
then I tried the following,
webClient.setCssEnabled(false);
webClient.setThrowExceptionOnFailingStatusCode(false);
webClient.setThrowExceptionOnScriptError(false);
And it just miracusly worked. cheers.

Resources