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
Related
I want selenium to force the browser to reload the page which it is loading if the loading process takes too long.
From StackOverflow I have that this code
new WebDriverWait(driver, 30).until((ExpectedCondition<Boolean>) wd -> ((JavascriptExecutor) wd)
.executeScript("return document.readyState").equals("complete"));
will wait until the page is fully loaded, but I want it to be reloaded if it takes more than 30 seconds.
How can I achieve that?
To reload the webpage incase the loading process is taking too long you can configure pageLoadTimeout. pageLoadTimeout sets the amount of time to wait for a page load to complete before throwing an error. If the timeout is negative, page loads can be indefinite.
An example (using Selenium v3.141.59 and GeckoDriver v0.24.0):
Code Block:
public class pageLoadTimeout
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS);
try{
driver.get("https://www.booking.com/hotel/in/the-taj-mahal-palace-tower.html?label=gen173nr-1FCAEoggJCAlhYSDNiBW5vcmVmaGyIAQGYATG4AQbIAQzYAQHoAQH4AQKSAgF5qAID;sid=338ad58d8e83c71e6aa78c67a2996616;dest_id=-2092174;dest_type=city;dist=0;group_adults=2;hip_dst=1;hpos=1;room1=A%2CA;sb_price_type=total;srfid=ccd41231d2f37b82d695970f081412152a59586aX1;srpvid=c71751e539ea01ce;type=total;ucfs=1&#hotelTmpl");
// do your other work here
}catch(WebDriverException e){
System.out.println("WebDriverException occured");
}
driver.quit();
}
}
Console Output:
1565680787633 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Debanjan.B\\AppData\\Local\\Temp\\rust_mozprofile.3jw3aiyfNAiQ"
1565680826515 Marionette INFO Listening on port 56499
1565680827329 Marionette WARN TLS certificate errors will be ignored for this session
Aug 13, 2019 12:50:28 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Aug 13, 2019 12:50:31 PM org.openqa.selenium.remote.ErrorCodes toStatus
WebDriverException occured
You can find a relevant discussion in pageLoadTimeout in Selenium not working
You can find a detailed discussion in Do we have any generic function to check if page has completely loaded in Selenium
WebDriverWait with through timeout exception. Put your code inside try/catch and reload the page on timeout exception:
try {
new WebDriverWait(driver, 30).until((ExpectedCondition<Boolean>) wd -> ((JavascriptExecutor) wd)
.executeScript("return document.readyState").equals("complete"));
} catch (TimeoutException e) {
// log a timeout
// System.out.println("Page load timeout, refresh.");
driver.navigate().refresh();
}
Try _driver.Navigate().Refresh();
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
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
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.
I'm trying to do a scraping exercise with Selenium, but I'm having a few problems.
Here is my code:
package ScraperPakage;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import java.util.List;
public class ScraperClass {
public static void main(String[] args) {
//Create a new instance of Firefox Browser
System.setProperty("webdriver.gecko.driver", "C:\\Users\\xxxx\\Selenium\\geckodriver-v0.10.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
//Open the URL in firefox browser
driver.get("http://www.budgettravel.ie");
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
List<WebElement> titles = driver.findElements(By.cssSelector("div.travelOfferList"));
for (int j = 0; j < titles.size(); j++) {
System.out.println( "\t - " + titles.get(j).getText() ) ;
}
driver.quit();
}
}
The code returns the list of offer holidays, but ends with a list of errors that I don't know how to resolve.
Here is the output:
JavaScript warning: resource://cck2/CCK2.jsm, line 998: unreachable code after return statement
JavaScript warning: resource://cck2/Preferences.jsm, line 556: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
1472551987508 Marionette INFO Listening on port 62410
JavaScript warning: https://normandy.cdn.mozilla.net/static/bundles/selfrepair-068962304d04a2173e88.94ed0f93a4f3.js, line 11002: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
Page title is: Cheap Holidays 2016/ 2017, Cheap Sun Holidays from Dublin, All Inclusive Sun Package Holidays from Ireland, Cheap Last Minute Holidays & Deals, All Inclusive Late Holiday Deals - Budget Travel
- Last Minute Deals
Where
When
Nights
From
Costa Blanca
21 Sep
7
€185pp
[ ... REST OF THE LIST ...]
Costa Dorada
22 Oct
7
€146pp
[Child 14212] WARNING: pipe error: 232: file c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 487
[Child 14212] ###!!! ABORT: Aborting on channel error.: file c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/glue/MessageChannel.cpp, line 2027
[NPAPI 13576] ###!!! ABORT: Aborting on channel error.: file c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/glue/MessageChannel.cpp, line 2027
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: 'unknown', revision: '2aa21c1', time: '2016-08-02 14:59:43 -0700'
System info: host: 'xxxx', ip: 'xxxx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_101'
Driver info: driver.version: RemoteWebDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, appBuildId=20160623154057, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, browserVersion=47.0.1, platformVersion=6.1, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=Firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=Windows_NT, device=desktop}]
Session ID: 3ad95378-01d1-4c6c-a3ce-24f992fb5289
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:670)
[... OTHER LINES LIKE THE LINE JUST ABOVE ...]
Also, the are two windows opening with 'Plugin Container for Firefox has stopped working'
Problem signature:
Problem Event Name: APPCRASH
Application Name: plugin-container.exe
Application Version: 47.0.1.6018
Application Timestamp: 576c9637
Fault Module Name: mozglue.dll
Fault Module Version: 47.0.1.6018
Fault Module Timestamp: 576c85ba
Exception Code: 80000003
Exception Offset: 0000f02b
OS Version: 6.1.7601.2.1.0.256.4
Locale ID: 6153
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
Any ideas why I'm getting the errors at the end and the windows opening at the end.
Thanks