Selenium + IntelliJ: annoying warnings, how to fix them - java

I always get the following warnings when i ty to execute my code...
The code works but it is annoying and i would like to fix it!
1580642544984 mozrunner::runner INFO Running command: "/usr/lib/firefox/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilevW0se4"
1580642546026 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid host permission: resource://pdf.js/
1580642546027 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid host permission: about:reader*
(firefox:7348): Gtk-WARNING **: 12:22:26.596: Theme parsing error: <data>:1:34: Expected ')' in color definition
(firefox:7348): Gtk-WARNING **: 12:22:26.596: Theme parsing error: <data>:1:77: Expected ')' in color definition
1580642549203 Marionette INFO Listening on port 43209
1580642549310 Marionette WARN TLS certificate errors will be ignored for this session
Feb. 02, 2020 12:22:29 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
And here the code:
package com.Selenium_intelliJ;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Main {
public static void search(WebDriver obj, String search){
obj.findElement(By.name("q")).sendKeys(search);
obj.findElement(By.xpath("/html/body/div/div[3]/form/div[2]/div[1]/div[3]/center/input[1]")).submit();
}
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "/home/josef/Java/geckodriver/geckodriver");
WebDriver obj = new FirefoxDriver();
obj.get("https://www.google.com/xhtml");
search(obj, "test");
}
}
Thanks in advance!

Related

I unable to get list of elements & list size? After entering "Gorav" in google search box

Console Error log is given below
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
1650804898952 geckodriver INFO Listening on 127.0.0.1:64899
1650804899967 mozrunner::runner INFO Running command: "C:\Program Files\Mozilla Firefox\firefox.exe" "--marionette" "--remote-debugging-port" "54286" "-no-remote" "-profile" "C:\Users\gorav\AppData\Local\Temp\rust_mozprofile0NSaWO"
1650804900257 Marionette INFO Marionette enabled
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new NotFoundError("Could not open the file at C:\Users\gorav\AppData\Local\Temp\rust_mozprofile0NSaWO\search.json.mozlz4", (void 0)))
DevTools listening on ws://localhost:54286/devtools/browser/03ef91a7-9e1e-4c23-899c-76257a8cced3
1650804902076 Marionette INFO Listening on port 53496
1650804902128 RemoteAgent WARN TLS certificate errors will be ignored for this session
Apr 24, 2022 6:25:02 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
List Size- 0
1650804904576 CDP ERROR Invalid browser preferences for CDP. Set "fission.webContentIsolationStrategy"to 0 and "fission.bfcacheInParent" to false before Firefox starts.
Apr 24, 2022 6:25:04 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found exact CDP implementation for version 85
1650804904596 Marionette INFO Stopped listening on port 53496
###!!! [Parent][PGPUParent] Error: RunMessage(msgname=PGPU::Msg_ShutdownVR) Channel closing: too late to send/recv, messages will be lost
```
package com.test;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GetListelements {
static WebDriver driver;
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.gecko.driver","C:\\Users\\gorav\\Downloads\\New folder\\geckodriver.exe");
driver = new FirefoxDriver();
driver.get("https://www.google.com/");
WebElement entertext = driver.findElement(By.xpath("//input[#class='gLFyf gsfi']"));
entertext.sendKeys("Gorav");
[enter image description here][1]
List<WebElement> list= driver.findElements(By.xpath("//ul//div//ul//li[#data-view-type='1']"));
//List<WebElement> list= driver.findElements(By.xpath("//ul//li[#role='presentation']"));
Thread.sleep(1000);
System.out.println("List Size- " +list.size());
for(WebElement b:list)
{
String Str=b.getText();
System.out.println(Str);
}
driver.close();
}
}
```

java.lang.IllegalMonitorStateException (java selenium)

package main_files;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class main_downloader {
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.gecko.driver", "path\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.wait(1);
driver.get("https://www.google.com/");
driver.wait(5);
driver.quit();
}
}
for some reason when I try to run this code it gives me this Error
1597445198205 geckodriver INFO Listening on 127.0.0.1:7834
1597445198836 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\ahmed\\AppData\\Local\\Temp\\rust_mozprofileinTqzS"
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
console.error: SearchCache: "_readCacheFile: Error reading cache file:" (new Error("", "(unknown module)"))
1597445201342 Marionette INFO Listening on port 22663
1597445201445 Marionette WARN TLS certificate errors will be ignored for this session
Aug 15, 2020 1:46:41 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Exception in thread "main" java.lang.IllegalMonitorStateException
at java.lang.Object.wait(Native Method)
at main_files.main_downloader.main(main_downloader.java:10)
i've tried some solutions but nothing worked !, could anyone help please !? Thx.
wait() function call must be called from Synchronized block to avoid this exception.
Do you want to sleep the main thread , if yes please use Thread.sleep() instead of wait() function call.

How to address the log INFO Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()` in selenium project

I just started a selenium project, but things didn't got right, so after searching a bit I found this solution. It works but i can't understand what these red statements want me to do, or how to get rid of them.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.*;
public class SelTest1
{
public static void main(String [] args)
{
System.setProperty("webdriver.gecko.driver","X:\\Gecko\\geckodriver-v0.24.0-win64\\geckodriver.exe");
File pathBinary = new File("X:\\FireFoxx\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
DesiredCapabilities desired = DesiredCapabilities.firefox();
FirefoxOptions options = new FirefoxOptions();
desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));
WebDriver obj = new FirefoxDriver(options);
obj.get("http://www.google.com/");
}
}
I got the result i wanted, but I don't understand the warning{ red statements}
I am putting those red lines { warnings here too for ease }
Jul 12, 2019 7:07:28 PM org.openqa.selenium.remote.DesiredCapabilities firefox
INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
1562938650997 mozrunner::runner INFO Running command: "X:\\FireFoxx\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\adars\\AppData\\Local\\Temp\\rust_mozprofile.uTUmeENutxin"
1562938652637 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1562938652638 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1562938652638 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: about:reader*
1562938655909 Marionette INFO Listening on port 50040
1562938655964 Marionette WARN TLS certificate errors will be ignored for this session
Jul 12, 2019 7:07:36 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
This INFO log message:
INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
is the result of the changes incorporated in:
Selenium v3.0.0-beta4
Added ability to use FirefoxOptions when starting firefox.
Selenium v3.5.0
* Start making *Option classes instances of Capabilities. This allows
the user to do:
`WebDriver driver = new RemoteWebDriver(new InternetExplorerOptions());`
If your usecase is to explicitly mention the absolute location of the FirefoxBinary you can use the following solution:
Using FirefoxOptions:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
public class A_Firefox_binary
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver(options);
driver.get("https://stackoverflow.com");
System.out.println("Page Title is : "+driver.getTitle());
driver.quit();
}
}
Console Output:
Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers

Selenium - Firefox - Java - Gecko - Warning message

I get a warn message when I try this code but the test case execute successfully.
Code
package test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class teatcalss {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.gecko.driver", "D:\\java\\geckodriver-v0.14.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://newtours.demoaut.com";
String expectedTitle = "Welcome: Mercury Tours";
String actualTitle = "";
// launch Firefox and direct it to the Base URL
driver.get(baseUrl);
// get the actual value of the title
actualTitle = driver.getTitle();
/*
* compare the actual title of the page witht the expected one and print
* the result as "Passed" or "Failed"
*/
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
//close Firefox
driver.close();
// exit the program explicitly
System.exit(0);
}
}
Warning message
1486664295999 geckodriver INFO Listening on 127.0.0.1:44072
Feb 09, 2017 10:18:16 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
1486664297761 mozprofile::profile INFO Using profile path C:\Users\Radwa\AppData\Local\Temp\rust_mozprofile.DhhwmmiiHibT
1486664297779 geckodriver::marionette INFO Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe
1486664297822 geckodriver::marionette INFO Connecting to Marionette on localhost:10262
[GFX1-]: CreateShaderResourceView failed for format87
1486664301804 Marionette INFO Listening on port 10262
[GFX1-]: CreateShaderResourceView failed for format87
Feb 09, 2017 10:18:29 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Test Passed!
This is a known message. See here for more info and discussion.
Bottom line, it's not an error, it won't break anything. If something gets screwed up, then that's when it's a good time to investigate. As it is right now, you can safely ignore it.
You can use the below code with your scripts, which will redirects these low level logs to a separate file rather than the console -
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"C:\\temp\\logs.txt");
For more information, you check refer this article - Disable Firefox logs

Detected borken kqueue while running the Java code in Selenium

I am getting the following problems with Selenium Test Run. I am using the tests to create and run on macSierra (10.12) Processor 2.8 GHz Intel Core i7.
I have installed Eclipse, Selenium and Java files from Selenium site.
Here is my code :
package com.some.seleniumproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.*;
import org.openqa.selenium.WebDriver.*;
import org.openqa.selenium.firefox.*;
public class sampleTest1 {
public static void main (String[] args) {
System.setProperty("webdriver.gecko.driver", "//Library/Java/geckodriver");
WebDriver driver=new FirefoxDriver();
String baseUrl = "http://www.seleniumhq.org";
String et = "Selenium - Web Browser Automation";
driver.get(baseUrl);
String rt = driver.getTitle();
if (rt.contentEquals(et)) {
System.out.println("Title is matched");
}
else {
System.out.println("Title is not matched");
}
driver.close();
}
}
Here are the errors :
1 :
1477536446864 geckodriver INFO Listening on 127.0.0.1:11419
Oct 26, 2016 7:47:27 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1477536448247 mozprofile::profile INFO Using profile path /var/folders/dk/xyw6v2zd1bd5sp8pd_4f8fpw0000gn/T/rust_mozprofile.jDvUQye5JfoO
1477536448249 geckodriver::marionette INFO Starting browser /Applications/Firefox.app/Contents/MacOS/firefox-bin
1477536448307 geckodriver::marionette INFO Connecting to Marionette on localhost:56571
[warn] kq_init: detected broken kqueue; not using.: Undefined error: 0
1477536450843 Marionette INFO Listening on port 56571
1477536453622 Marionette INFO startBrowser dab7ebb7-1664-6943-9cc4-e3817dd3a894
Oct 26, 2016 7:47:34 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[warn] kq_init: detected broken kqueue; not using.: Undefined error: 0
However, the above error maybe, correct result is thrown in the output.
2 :
Note: This element has neither has attached source nor attached Java doc and hence no Java
doc could be found. - this is for the step driver.close();
Please help.
I've found this bug reported in Mozilla - https://bugzilla.mozilla.org/show_bug.cgi?id=1304266. Read a comment to it.
It looks like libevent issue can cause the problem you've described.

Categories

Resources