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
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.
My Code :
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class FirstAutomation {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\sony\\Downloads\\chromedriver_win32.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://wwww.google.com");
}
}
Exceptions
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Users\sony\Downloads\chromedriver_win32.exe
at com.google.common.base.Preconditions.checkState(Preconditions.java:534)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:131)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123)
at FirstAutomation.main(FirstAutomation.java:8)
Please follow the below steps to add the Chromedriver.exe
Right Click on your Selenium Project -> Build Path -> Configure Build Path -> Libraries -> Add External Class Folder
Note: kindly cross-check the chrome driver Path location in your pc and make sure the chrome driver version and google chrome version's match each other
Link to download the latest Chrome Driver
I hope the above process Works
Thanks to Vikas Dadi. I had downloaded chrome driver of 80 version and the actual browser being used on the laptop was 79, hence the error. But now it is working fine after deleting the driver and reinstalling the driver of the same version.
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.
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
I want to fill web form in bot way. I added the libraryclient-combined 3.0.0 beta 3 to the document .My firefox version should be most updated .
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Selenium {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("https://mail.google.com");
driver.findElement(By.id("Email")).sendKeys("yourEmailId");
driver.findElement(By.id("Passwd")).sendKeys("yourPassword");
driver.findElement(By.id("signIn")).click();
}
}
However , error comes out .
In my understanding , the seleniums 3.0 jar version should be along with geckodriver . Then ,i try to install geckodriver v10.0 here.
https://github.com/mozilla/geckodriver/releases
When I execute the geckodriver-v0.10.0-win64.zip , the installer can't be installed -only black window comes out .
What's wrong ?
REMARK: x64 window 10 version
you can use marionette driver which i recently used. You need to download and rename it to wires.exe. you can download from the following link
https://github.com/mozilla/geckodriver/releases
You need to add selenium-2.53.0 jar files.
below is the code you need to write.
System.setProperty("webdriver.gecko.driver", "G:\\ravik\\Ravi-Training\\Selenium\\Marionette for firefox\\wires.exe");
WebDriver driver = new MarionetteDriver();
driver.get("https://www.google.co.in/webhp?hl=en&sa=X&ved=0ahUKEwjdgc21jJHOAhVCvY8KHZ4aCdcQPAgD");
System.out.println("marionette working fine....");
To all those that are still confused:
What's wrong ?
Well, nothing is wrong, you just need to understand that geckodriver.exe is the driver itself, not an installer that will eventually install the driver on your machine.
So there are two steps you need to do in order to use (or let's say install) the driver:
Unzip the folder on your machine (which you already did) and
Add the driver executable path to test properties (the thing that Ravi pointed out)
Additional note: I use Intellij IDEA to run my tests, so I simply edit the test run configuration and add this line:
-Dwebdriver.gecko.driver="Path\to\my\geckodriver.exe"