How to turn off the Marionette/gecko driver logs in selenium 3 - selenium

I need to turn off the Marionette/GeckoDriver logging; is there is any way to do that? I've been searching a lot, but I am not getting the proper answer.
The INFO logs were:
1484653905833 geckodriver INFO Listening on 127.0.0.1:15106
Jan 17, 2017 5:21:46 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1484653906715 mozprofile::profile INFO Using profile path C:\Users\vtiger\AppData\Local\Temp\3\rust_mozprofile.7d2LEwDKoE8J
1484653906720 geckodriver::marionette INFO Starting browser C:\Program Files\Mozilla Firefox\firefox.exe
1484653906731 geckodriver::marionette INFO Connecting to Marionette on localhost:58602
1484653908388 addons.manager DEBUG Application has been upgraded
1484653908843 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: ["XPIProvider"]
1484653908846 addons.manager DEBUG Loaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: ["LightweightThemeManager"]
1484653908852 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/GMPProvider.jsm
1484653908855 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/PluginProvider.jsm
1484653908857 addons.manager DEBUG Starting provider: XPIProvider
1484653908857 addons.xpi DEBUG startup
1484653908858 addons.xpi INFO SystemAddonInstallLocation directory
How do I turn off this logging?

You can disable the logs by sending them to /dev/null via a system property like so:
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
return new FirefoxDriver();

Working solution on Windows and Linux.
# python 3
# windows
PATH_TO_DEV_NULL = 'nul'
FIREFOX_DRIVER_PATH = 'D:\\path\\to\\geckodriver.exe'
# linux
PATH_TO_DEV_NULL = '/dev/null'
FIREFOX_DRIVER_PATH = '/path/to/geckodriver'
# start browser
driver = webdriver.Firefox(executable_path=FIREFOX_DRIVER_PATH,
service_log_path=PATH_TO_DEV_NULL)

Tried the following code, but didn't work. Seems like a bug in selenium 3.0
LoggingPreferences pref = new LoggingPreferences();
pref.enable(LogType.BROWSER, Level.OFF);
pref.enable(LogType.CLIENT, Level.OFF);
pref.enable(LogType.DRIVER, Level.OFF);
pref.enable(LogType.PERFORMANCE, Level.OFF);
pref.enable(LogType.PROFILER, Level.OFF);
pref.enable(LogType.SERVER, Level.OFF);
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, pref);
WebDriver driver = new FirefoxDriver(desiredCapabilities);
driver.get("https://www.google.com/");
driver.findElement(By.id("lst-ib")).sendKeys("something");
Thread.sleep(2000);
driver.quit();

One option that has worked for some is proposed here, and uses a batch file to pass in command line arguments to the executable. Unfortunately, this oftentimes leaves extra processes open (geckodriver.exe, cmd.exe) and no solution to this next problem has been proposed as of yet...

GeckoDriverService gecko = new GeckoDriverService(new File("c:/selenium/geckodriver.exe"), 4444, ImmutableList.of("--log=fatal"), ImmutableMap.of());
gecko.sendOutputTo(new FileOutputStream("gecko_log.txt"));
gecko.start();
FirefoxOptions opts = new FirefoxOptions().setLogLevel(Level.OFF);
DesiredCapabilities capabilities = opts.addTo(DesiredCapabilities.firefox());
capabilities.setCapability("marionette", true);
FirefoxDriver driver = new FirefoxDriver(gecko, capabilities);

This might be a bit hacky but it can quickly get the job done. Given that you know the exact location of your file and you run your code on Linux you can just cd into that dir and
rm geckodriver.log
ln -s /dev/null geckodriver.log

service_log_path seems to be deprecated in python:
driver.py:77: DeprecationWarning: service_log_path has been deprecated, please pass in a Service object
This worked for me now:
from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium import webdriver
service = FirefoxService(driver_path, log_path='nul') # Disable logs in windows, for linux probably /dev/null
driver = webdriver.Firefox(
service=service
)

Related

WebDriverException (Status code 127) when running Selenium + webdriver_manager on gitlab-CI machine (linux)

I'm running a simple CI pipeline on GitLab for a Selenium script headlessly + using webdriver_manager to handle chrome driver binary.
This part is passed:
Get LATEST chromedriver version for None google-chrome
There is no [linux64] chromedriver for browser None in cache
Trying to download new driver from https://chromedriver.storage.googleapis.com/100.0.4896.60/chromedriver_linux64.zip
Driver has been saved in cache [/root/.wdm/drivers/chromedriver/linux64/100.0.4896.60]
But after that I'm getting this error:
WebDriverException: Message: Service /root/.wdm/drivers/chromedriver/linux64/100.0.4896.60/chromedriver unexpectedly exited. Status code was: 127`
What is the problem? Seems like webdriver_manager has a problem by running in CI.
Here is a simple script for reproduce:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=chrome_options)
driver.get("http://google.com")
driver.find_element('name', 'q').send_keys("Wikipedia")
This is one of the pipelines:
https://gitlab.com/mmonfared/test/-/jobs/2350697126
This is a sample project:
https://gitlab.com/mmonfared/test
I've also opened an issue in webdriver_manager github repo, no answers yet:
https://github.com/SergeyPirogov/webdriver_manager/issues/363
This error message...
WebDriverException: Message: Service /root/.wdm/drivers/chromedriver/linux64/100.0.4896.60/chromedriver unexpectedly exited. Status code was: 127`
...implies that you are executing your tests as the root user.
Deep Dive
As per Chrome doesn't start or crashes immediately
A common cause for Chrome to crash during startup is running Chrome as
root user (administrator) on Linux. While it is possible to work
around this issue by passing --no-sandbox flag when creating your
WebDriver session, such a configuration is unsupported and highly
discouraged. Please configure your environment to run Chrome as a
regular user instead.
Solution
Execute your tests as a non-root user.

Error: Can't find profile directory. console.warn: SearchSettings: "get: No settings file exists, new profile?" using GeckoDriver Firefox and Selenium

[RemoteTestNG] detected TestNG version 7.3.0
1609754675168 geckodriver INFO Listening on 127.0.0.1:123456
1609754675873 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\username\\AppData\\Local\\Temp\\rust_mozprofileomKd1k"
Can't find symbol 'eglSwapBuffersWithDamageEXT'.
Can't find symbol 'eglSetDamageRegionKHR'.
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
1609754679973 Marionette INFO Listening on port 53339
1609754680041 Marionette WARN TLS certificate errors will be ignored for this session
Jan 04, 2021 3:34:40 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
FirefoxDriver: firefox on WINDOWS (f53578b1-71b7-46a7-85ef-8bfd18ba1bc2)
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.poi.openxml4j.util.ZipSecureFile$1 (file:/C:/Users/S%20K%M/.m2/repository/org/apache/poi/poi-ooxml/3.17/poi-ooxml-3.17.jar) to field java.io.FilterInputStream.in
WARNING: Please consider reporting this to the maintainers of org.apache.poi.openxml4j.util.ZipSecureFile$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
JavaScript warning: https://resulticks.team/Scripts/Commonfunction.js, line 147: unreachable code after return statement
JavaScript warning: https://resulticks.team/Scripts/Commonfunction.js, line 147: unreachable code after return statement
1609754783815 Marionette INFO Stopped listening on port 53339
###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost
log4j:WARN No appenders could be found for logger (freemarker.cache).
log4j:WARN Please initialize the log4j system properly.
Given implicit wait time
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Same code working in chrome..
For firefox below code used for launch:
private synchronized ThreadLocal createFirefoxDriver()
{ // FF Profile
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "/driver/geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("Selenium");
FirefoxOptions foptions = new FirefoxOptions();
foptions.setProfile(testprofile);
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("marionatte", false);
foptions.merge(dc);
driver.set(new FirefoxDriver(foptions));
return driver;
}
Thanks #DebanjanB..Still my issue not resolved.. After running script by using profile
[RemoteTestNG] detected TestNG version 7.3.0
1609825445685 geckodriver INFO Listening on 127.0.0.1:2634
1609825469323 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\SKMAST~1\\AppData\\Local\\Temp\\rust_mozprofileVF0L8V"
Can't find symbol 'eglSwapBuffersWithDamageEXT'.
Can't find symbol 'eglSetDamageRegionKHR'.
1609825472726 Marionette INFO Listening on port 64263
1609825473031 Marionette WARN TLS certificate errors will be ignored for this session
Jan 05, 2021 11:14:33 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
JavaScript warning: https://weburl/Scripts/Commonfunction.js, line 147: unreachable code after return statement
1609825500246 Marionette INFO Stopped listening on port 64263
JavaScript error: https://weburl/DashBoard/Index, line 2521: ReferenceError: LoadingPanelDisplay is not defined
###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost
log4j:WARN No appenders could be found for logger (freemarker.cache).
log4j:WARN Please initialize the log4j system properly.
My Issue is
In my application after login, trying to find element without loading page element found message and capturing screenshot. in another case after login, I have to click element without loading page element clicked message showing after few seconds page loaded. but same code working in chrome.
This error message...
Can't find symbol 'eglSwapBuffersWithDamageEXT'.
Can't find symbol 'eglSetDamageRegionKHR'.
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
...implies that the firefox-profile by the name Selenium doesn't exist.
Solution
Before you try to access the firefox-profile by the name Selenium you have to create it first following the steps mentioned in Creating a new Firefox profile on Windows
References
You can find a couple of relevant detailed discussions in:
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) using Selenium and Java
Cannot resolve constructor FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)
How to use both the Firefox Profile and Firefox options with Selenium in Java
Selenium Tests take several minutes to start when loading a profile

Selenium Grid: RemoteWebDriver blocks the execution

I am new on using Selenium and I faced some questions on using RemoteWebDriver in Selenium Grid 2. I would like to what's wrong in my code. Thanks.
I set the RemoteWebDriver in 3 steps:
Set the Chrome driver to system property, I checked the path is correct.
Set the capabilities
Turn on the driver by RemoteWebDriver
logger.info("1. Start");
File file = new File("/path/of/chromedriver");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
logger.info("2. Get Path: " + file.getAbsolutePath());
DesiredCapabilities caps = new DesiredCapabilities();
caps.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
logger.info("3. Set capabilities: " + caps);
URL url = new URL(URL);
RemoteWebDriver driver = new RemoteWebDriver(url, caps);
logger.info("4. Initialize driver: " + driver);
logger.info("5. End");
return driver;
The result pass first 2 steps but fail in the last step because the log does not show. It seems there is a problem in setting RemoteWebDriver. The log is shown as below:
May 16, 2017 8:28:16 PM com.test.Setup setupDriver
INFO: 1. Start
May 16, 2017 8:28:16 PM com.test.Setup setupDriver
INFO: 2. Get Path: /path/of/chromedriver
May 16, 2017 8:28:16 PM com.test.Setup setupDriver
INFO: 3. Set capabilities: Capabilities [{browserName=chrome}]
May 16, 2017 8:28:16 PM com.test.Setup setupDriver
SEVERE: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
Can anyone suggest where is the problem, thanks!
selenium-server-standalone-3.4.0.jar
selenium-java-3.4.0
chromedriver 2.29
java version "1.8.0_111"
TestNG
The exception says it all.
May 16, 2017 8:28:16 PM com.test.Setup setupDriver SEVERE: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
Please ensure you do the following on the machine in which you are running the node.
Have the location of the chromedriver binary made available as part of your PATH environment variable.
Now to ensure that the location is properly set, open up a new command prompt/terminal and type chromedriver.
You should see an output as below (my output is from a MAC)
12:16 $ chromedriver
Starting ChromeDriver 2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b) on port 9515
Only local connections are allowed.
Once you see a similar output, you can try running your test again and you should be fine.

NullPointer Exception In running testCases via Selenium webDriver in Chrome

I am trying to run my test cases on Chrome and I had copied the path in the Properties file,but still console is throwing annoying statements like:
ERROR: The path to the chromedriver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromium/downloads/list
FAILED CONFIGURATION: #BeforeTest startWebSession
java.lang.NullPointerException
One thing I have found is that the Chrome driver cannot be started from within Eclipse. It must be run from a command prompt. At least on Windows 7 64-bit.
Trying to run it from within Eclipse produces this exception:
Exception in thread "main" java.lang.IllegalStateException: The webdriver.chrome.driver system property defined chromedriver executable does not exist: C:\Windows\System32\chromedriver.exe
This problem only occurs for Chrome. IE and FireFox work fine from within Eclipse.
Download the chrome driver from http://code.google.com/p/chromedriver/downloads/list
Initialize your driver object in the following manner -
System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
By doing this the chrome driver works properly.
This is how do I initialize the ChromeDriver:
public RegulationUI() throws Exception{
ChromeDriverService service = ChromeDriverService.createDefaultService();
File file = new File(RegulationUI.class.getResource("/chromedriver.exe").toURI());
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, file.getAbsolutePath());
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
driver = new ChromeDriver(service,options);
}
BTW my test class is named RegulationUI
Try this, it works for me and moreover, I know that this is "multicomputer" solution - our project is in subversion and this way everybody can run it, even if we have differently setup where exactly on disk the "working folder" for IDE is
Please download chromedriver.exe for Google chrome browser
please download IEdriver.exe for Internet explore.
Please And kept these files in a root folder of windows for simplicity. Lets consider your operating systems installed on c:\ (C Driver) create a folder name Selenium on C-Drive and Kept these binary(.exe) files. like c:\selenium
in your Testcase/testScript Write as
//For Chrome Browser:
Webdriver driver = new ChromeDriver();
java.io.File file = new File("c:\\selenium\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
If you are using maven then try to use following in your pom:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>RELEASE</version>
</dependency>
and use it like this for chrome in your setup:
ChromeDriverManager.getInstance().setup();
driver = new ChromeDriver();

Unable to find/open Firefox Binary - webdriver/robot framework

Unable to find/open Firefox Binary - webdriver/robot framework
My tests run fine in java and fitnesse. They also run fine when executing them through robot framework with Internet Explorer and Chrome. However when I execute them through Firefox, using 'new FirefoxDriver()', I receive the following error:
DEBUG java.lang.ExceptionInInitializerError
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java: 81)
Caused by: java.lang.NullPointerException
org.openqa.selenium.firefox.FirefoxBinary.<clinit>(FirefoxBinary.java: 42)
... 183 more
In the FirefoxBinary and FirefoxDriver classes these lines correspond to the following code:
FirefoxBinary ln42-43
private static final String PATH_PREFIX = "/" +
FirefoxBinary.class.getPackage().getName().replace(".", "/") + "/";
and FirefoxDriver ln 80-82
public FirefoxDriver(FirefoxProfile profile) {
this(new FirefoxBinary(), profile);
}
I have tried setting the path to the Firefox binary in my classpath, pythonpath (used by robotframework) and path. I have also written the following lines of code to try to force the binary to be found:
System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(FirefoxDriver.BINARY, "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
I have tried to execute the tests on two computers, my work and home machines. Further I have tried to use a firefox profile created using firefox.exe –p and also by creating one in the java code. I have tried Firefox 6-8. Unfortunately none of these things have worked.
I am also using/have used:
Java 1.6
Selenium 2.9.0/2.13.0
Windows 7
I am unsure if this is related but as a work around I have been trying to get Firefox to run through a remote browser. I have been trying the following code:
rcc = new RemoteControlConfiguration();
rcc.setPort(4447);
rcc.setPortDriversShouldContact(4447);
rcc.setInteractive(true);
rcc.setSingleWindow(true);
rcc.setTimeoutInSeconds(30);
ss = new SeleniumServer(rcc);
ss.start();
DesiredCapabilities cap = new DesiredCapabilities();
cap.setJavascriptEnabled(true);
cap.setBrowserName("firefox");
URL url = new URL ("http://www.google.com/");
driver = new RemoteWebDriver(url,cap);
However when I run the above I get the following error message:
Exception in thread "main" org.openqa.selenium.WebDriverException: Error communicating with the remote browser. It may have died.
Build info: version: '2.13.0', revision: '14794', time: '2011-11-18 17:49:47'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0'
Driver info: driver.version: Selenium2Driver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:412)
Does anyone have any idea on how to fix either of my problems?
Any help would be greatly appreciated, I feel very stuck on this issue atm. Two days of trying to get Firefox to work when Internet Explorer already does….. It feels as if the world is about to end.
Thanks,
James
EDIT:1
It is possible for me to run Firefox by using selenium-server.
James, FYI, URL for RemoteWebDriver appears incorrect in post above. Should be something more like "localhost:4444/wd/hub";? Interestingly, I'm having the opposite problem with Web Driver, having issues starting Firefox via RemoteWebDriver but Firefox runs fine via native FirefoxDriver. IE works fine over remote. – David Dec 4 '11 at 4:51
Thanks David!
I am not understanding why you have not configured your Firefox binary in your remote grids config.json file? That's how I would do it. Then, your DesiredCapabilities object would not need to define it. A hint can be found here.
If it works, the line in the JSON file might look like:
"binary": "C:/Program Files/Mozilla Firefox/firefox.exe",
I guess it doesn't allow you to dynamically set the binary location from your code, but perhaps you can try it that way to prove if it should work or not as a troubleshooting step.
FirefoxProfile profile = new FirefoxProfile();
FirefoxBinary binary = new FirefoxBinary(new File("C:\\path to firefox\\firefox.exe"));
driver = new FirefoxDriver(binary, profile);
try this
This kind of issue obtained because of selenium web driver fail to find the .exe files of Firefox. Please check whether C:\Program Files (x86)\Mozilla Firefox you have exe file in the location and don’t forget to set environment variable having the java jdk path.
Source:- read [Solved Cannot find firefox binary in PATH Selenium][1]http://www.tech4crack.com/solved-cannot-find-firefox-binary-in-path/