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.
Related
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();
}
}
```
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.
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!
I have the next code, this code works with chrome driver but with phantom js 1.4.4 library and 2.1.1 driver is not working im not able to locate the elements
This issue doesnot appear with chrome driver.
Code trials:
public void test1()
{
DesiredCapabilities caps = new DesiredCapabilities();
((DesiredCapabilities) caps).setJavascriptEnabled(true);
((DesiredCapabilities) caps).setCapability("takesScreenshot",true);
((DesiredCapabilities) caps).setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "/Users/santiagogalicia/downloads/phantomjs");
caps.setJavascriptEnabled(true);
String [] phantomJsArgs = {"--web-security=no", "--ignore-ssl-errors=yes"};
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomJsArgs);
WebDriver driver = new PhantomJSDriver(caps);
Dimension dimension = new Dimension(400,600);
driver.manage().window().setSize(dimension);
driver.get("https://stage-commissionist.payclip.com/#/");
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.id("formUsername")));
driver.findElement(By.id("formUsername")).sendKeys(User);
driver.findElement(By.id("formPassword")).sendKeys(Password);
driver.findElement(By.cssSelector(".btn")).click();
driver.close();
}
I tried change the driver and with other driver works
The error that I am seeing:
[ERROR - 2019-02-07T19:15:26.476Z] Session [b736bad0-2b0c-11e9-b0db-6d1517ea5006] - page.onError - msg: ReferenceError: Can't find variable: Set phantomjs://platform/console++.js:263 in error
[ERROR - 2019-02-07T19:15:26.476Z] Session [b736bad0-2b0c-11e9-b0db-6d1517ea5006] - page.onError - stack:
(anonymous function) (https://stage-commissionist.payclip.com/static/js/1.ea7f0607.chunk.js:1)
f (https://stage-commissionist.payclip.com/#/:1)
phantomjs://platform/console++.js:263 in error
[ERROR - 2019-02-07T19:15:26.759Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1549566926721
As you mentioned this code works with chrome driver but with phantom js 1.4.4 library and 2.1.1 this error message...
[ERROR - 2019-02-07T19:15:26.476Z] Session [b736bad0-2b0c-11e9-b0db-6d1517ea5006] - page.onError - msg: ReferenceError: Can't find variable: Set phantomjs://platform/console++.js:263 in error
[ERROR - 2019-02-07T19:15:26.476Z] Session [b736bad0-2b0c-11e9-b0db-6d1517ea5006] - page.onError - stack: (anonymous function) (https://stage-commissionist.payclip.com/static/js/1.ea7f0607.chunk.js:1) f (https://stage-commissionist.payclip.com/#/:1)
phantomjs://platform/console++.js:263 in error [ERROR - 2019-02-07T19:15:26.759Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1549566926721
...implies that the PhantomJSDriver wasn't initiated properly.
As per the discussion in ReferenceError: Can't find variable: Set main reason seems that one of the previous version of PhantomJS didn't support ES2015 Set.
Solution
You can try the experimental branch of uncss that uses jsdom instead of PhantomJS by installing uncss-jsdom instead. You can find the merge in #265: Replace PhantomJS with jsdom. Here you can find the discussion on Consider jsdom
However, with Selenium v3.14.0 and phantomjsdriver-1.4.4.jar your code block initializes PhantomJSDriver and Ghost Browser just perfecto and you can use the following solution:
Code Block:
package phantomJSDriver;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
public class A_PhantomJS_DCap {
public static void main(String[] args) {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setJavascriptEnabled(true);
desiredCapabilities.setCapability("takesScreenshot", true);
desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
String [] phantomJsArgs = {"--web-security=no", "--ignore-ssl-errors=yes"};
desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomJsArgs);
WebDriver driver = new PhantomJSDriver(desiredCapabilities);
Dimension dimension = new Dimension(400,600);
driver.manage().window().setSize(dimension);
driver.get("https://www.google.co.in");
System.out.println(driver.getTitle());
driver.quit();
}
}
Console Output:
Feb 09, 2019 8:35:12 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: executable: C:\Utility\phantomjs-2.1.1-windows\bin\phantomjs.exe
Feb 09, 2019 8:35:12 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: port: 18249
Feb 09, 2019 8:35:12 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: arguments: [--web-security=no, --ignore-ssl-errors=yes, --webdriver=18249, --webdriver-logfile=C:\Users\AtechM_03\LearnAutmation\learn-automation\phantomjsdriver.log]
Feb 09, 2019 8:35:12 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: environment: {}
[INFO - 2019-02-09T15:05:14.986Z] GhostDriver - Main - running on port 18249
[INFO - 2019-02-09T15:05:16.008Z] Session [1b791e00-2c7c-11e9-9e77-ef7d90721101] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":false}
[INFO - 2019-02-09T15:05:16.008Z] Session [1b791e00-2c7c-11e9-9e77-ef7d90721101] - page.customHeaders: - {}
[INFO - 2019-02-09T15:05:16.008Z] Session [1b791e00-2c7c-11e9-9e77-ef7d90721101] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"windows-8-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO - 2019-02-09T15:05:16.008Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 1b791e00-2c7c-11e9-9e77-ef7d90721101
Feb 09, 2019 8:35:16 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Google
[INFO - 2019-02-09T15:05:20.866Z] ShutdownReqHand - _handle - About to shutdown
Note: As per your comment the site is only available by vpn, its a private site so the relevant code was tested with https://www.google.co.in
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