I have written a JAVA program which will trigger Chrome driver and open google.com the program works fine in eclipse so I created a JAR file.
Even the JAR file is working fine independently. It will open google.com in google chrome then its closing the chrome driver.
But I am trying to trigger this JAR through PHP now for some reason this is not working.
The PHP is not triggering the JAR file at all.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Chrome_Test {
public static void main(String[] args) {
// Telling the system where to find the Chrome driver
System.getProperty("user.dir" + "\\chromedriver.exe");
WebDriver webDriver = new ChromeDriver();
// Open google.com
webDriver.navigate().to("http://www.google.com");
// Printing result here.
WebDriverWait wait = new WebDriverWait(webDriver, 10);
webDriver.close();
webDriver.quit();
}
}
My PHP Code:
<?php
exec("java -jar TEST10.jar");
?>
TEST10 is the name of the JAR containing the above Java program.
Related
My distro doesn't provide a 'selenium' package
$ apt search selenium p libtest-www-selenium-perl - Perl test framework using Selenium Remote Control i A python3-selenium - Python3 bindings for Selenium p qunit-selenium - Run QUnit tests through Selenium WebDriver p ruby-selenium-webdriver.
I've tried this and this approaches and the browser does get invoked successfully. This is my code.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
//import selenium.webdriver;
//import selenium.webdriver.support.ui.WebDriverWait;
//import selenium.webdriver.common.by.By;
//import selenium.webdriver.support.expected_conditions;
import static org.openqa.selenium.By.*;
//import static sun.security.util.KnownOIDs.EC;
public class Login {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "./geckodriver");
WebDriver dr = new FirefoxDriver();
dr.get("https://google.com/");
dr.manage().window().maximize();
//Click on "Join now"
WebElement join = dr.findElement(xpath("//a[#class='newUser green']"));
//WebDriverWait(driver, 20).until(EC.element_to_be_clickable((xpath("//a[#class='newUser green']")))).click();
join.click();
}
}
My problem is uncommenting any of the imports breaks because java has no idea what a selenium is. How do I add it? Linux Mint.
Go to https://chromedriver.chromium.org/downloads page
Depends on your Chrome version, Download Linux chrome driver zip package
Unip package and locate under any folder that is in system PATH or add your folder to PATH
Go to https://www.selenium.dev/downloads/ and download Selenium Java package and locate it under your project's library package(depends on your project/IDE settings)
Welcome. There is a lot going on in your quesrion: intelij; Java class paths; import statements.
I recommend tackling it one at a time.
copy the java example on selenium.dev doco page.
Run commandline javac.exe directly javac command examples (code Java.net) look for the 'Compile a source file which depends on multiple libraries' example. NOTE: the import statements are class references... Don't use the filename (is different to python).
Search Web for how to configure classpath for intelij.
I am new in Automation testing.
Had created a simple program to Open URL in Firefox browser. Browser is getting opened without URL.
Someone please help.
package sanitytest;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Adminlogin {
public static void main(String[]args){
WebDriver driver = new FirefoxDriver();
driver.get("http://www.gcrit.com/build3/admin/login.php");
}
}
I am using Firefox version :- 47.0.1
eclipse mars version :- 4.5.0
Selenium webdriver version :- 2.51
For Mozila Firefox till version 46.x it was the legacy browser and we didn't need gecko driver. Mozila Firefox from version 47.x onwards comes with Marionette, which is an automation driver for Mozilla's Gecko engine. It can remotely control either the UI or the internal JavaScript of a Gecko platform, such as Firefox. Can be donwloaded here: https://github.com/mozilla/geckodriver/releases and needs selenium 3.x.
So, either downgrade FF to version 46.x, or use latest selenium binding with geckodriver + latest FF
Unfortunately Selenium WebDriver 2.51.0 is not compatible with Firefox 47.0. The WebDriver component which handles Firefox browsers (FirefoxDriver) will be discontinued.
Try using firefox 46.0.1. It best matches with Selenium 2.51
https://ftp.mozilla.org/pub/firefox/releases/
try the following code its working
package automation ;
import java.util.concurrent.TimeUnit
enter code here
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class test {
public static void main(String[] args) throws InterruptedException {
//Object webdriver;
System.setProperty("webdriver.gecko.driver",
"C:\\Users\\user\\Downloads\\geckodriver-v0.17.0-win64/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
driver.get("https://www.easybooking.lk");
String i = driver.getCurrentUrl();
System.out.println(i);
//driver.close();
}
}
if its not working http://www.seleniumhq.org/download/ here download java 3.4.0
then in eclipse, right click your project-->properties-->java build path--> liberies-->add external JARS..
enter image description here
Attempting to execute the following Selenium script results in a WebDriverException:
package package1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Class1 {
public static void main(String[] args) {
WebDriver driver= new FirefoxDriver();
driver.manage().window().maximize();
driver.close();
}
}
The exception thrown is
org.openqa.selenium.WebDriverException: Unable to bind to locking port 7054 within 45000 ms
at org.openqa.selenium.internal.SocketLock.lock(SocketLock.java:99)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:80)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:119)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:218)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at package1.Class1.main(Class1.java:12)
Why is this happening?
Used version- 1.8.0_101 java file
Neon eclipse
2.53 selenium jar file
You need to start the selenium server with the Firefox driver before running the test
I have written the following selenium script which opens Gmail website.
import org.openqa.selenium.WebDriver; <br>
import org.openqa.selenium.firefox.*;
public class OpenGmail {
/**
* #param args
*/
public void OpenGmailApp()
{
WebDriver webdriver = new FirefoxDriver();
webdriver.get("gmail URL");
}
public static void main(String[] args) {
OpenGmail ob = new OpenGmail();
ob.OpenGmailApp();
}
}
When I execute the above script, I'm getting Firefox home page only. Its not gmail login page. Kindly guide what could be the error I made in that script.
If your jar files are old and the browser was updated to latest version, then download the latest jar files from selenium website -
Selenium Download
You can also use the Selenium FF addon..
FF Selenium Addon
All the steps can be recorded in the addon and the script can be exported.
I have faced the same problem. Now issue is fixed. download the latest selenium jar and replace the external jar of project in eclipse. Check the selenium jars. Selenium supports Firefox so it directly initiate the instance of Firefox WebDriver, but due to selenium jars compatibility url id not opening.
http://www.seleniumhq.org/download/
This is due to the unsigned .xpi (selenium 2.45.0) not being loaded by firefox 43. It's a temporary fix. Selenium will be going to update their jar soon after this you will not need to use this profiling
Full Code:-
public void OpenGmailApp()
{
WebDriver driver = null;
final FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("xpinstall.signatures.required", false);
driver = new FirefoxDriver(firefoxProfile);
driver.get("https://www.google.co.in/");
}
public static void main(String[] args) {
OpenGmail ob = new OpenGmail();
ob.OpenGmailApp();
}
Another thing which can cause issue is either old selenium jars or old browser version. So update both of them.
Download latest jars from below URL:-
http://www.seleniumhq.org/download/
Hope it will help you :)
If you are running via Jenkins/Command prompt then along with updating your selenium jars, delete the older version of that particular jars in your library folder. Keeping both versions might create issue while running via Jenkins/Command prompt
I want to extract the last frame from the swf file using Java. However, after trying several ways to to do that, one way it worked is by using selenium to launch a browser, load the swf, wait for the last frame and take the snapshot. It works fine on my mac. The code is as below
package flash;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class snaphot_swf {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.get("file:///Users/test/Downloads/Car-speakers-590x90.swf");
Thread.sleep(10000);
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("/Users/test/Documents/screenshots/screenshot.png"));
driver.close();
System.out.print("snapshot taken");
}
}
I now want to do the same on a head less browser in Cent OS 6.4
I did the following:
//install firefox
yum install firefox
//install flash plugin
rpm -ivh http://linuxdownload.adobe.com/adobe-release/adobe-release-x86_64-1.0-1.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux
yum check-update
yum install flash-plugin nspluginwrapper alsa-plugins-pulseaudio libcurl
//install Xvfb
yum info xorg-x11-server-Xvfb
//starting Xvfb
/usr/bin/Xvfb :1 -screen 0 1024x768x24 &
export DISPLAY=:1
Now, when I run my Java code for a png file by loading it in the firefox browser and taking snapshot, it works perfectly well. However, when I try to load the swf file I get a blank snapshot.
How can I load the swf in Firefox and obtain a snapshot