Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

0
Automating web application with Jacob api and selenium is produces UnsatisfiedLinkError

Open 1 Answers 79 Views
0 1
I have used Jacob Api for uploading files on automating web application with selenium, but it produces UnsatisfiedLinkError. Am new for Jacob api to file upload so please help and thanks in advance.

Source Code:-

public class FileUpload {
    public static void main(String a[]){
        WebDriver driver;
        try {
            System.setProperty("webdriver.chrome.driver", "/home/ionixx/workspace/IXAutomateNew1/chromedriver/chromedriver_linux");
            driver = new ChromeDriver();
            driver.manage().window().maximize();
            driver.navigate().to("http://test/admin/#/login");
            driver.findElement(By.id("email")).sendKeys("admin.com");
            driver.findElement(By.id("pass")).sendKeys("test");
            driver.findElement(By.className("adm-button-action")).click();
            Thread.sleep(5000);
            driver.findElement(By.xpath("html/body/div[1]/app-root/div/div[2]/div/app-project/div/div/div/div[1]/div/div[1]/h4/button")).click();
            driver.findElement(By.xpath("html/body/div[1]/app-root/div/div[2]/div/app-project/div/div/div/div[1]/div/div[2]/div[3]/div[5]/div/div[2]/label[1]")).click();
            String workingDir = System.getProperty("user.dir");
            final String jacobdllarch = System.getProperty("sun.arch.data.model")
                    .contains("32") ? "jacob-1.18-x86.dll" : "jacob-1.18-x64.dll";
            String jacobdllpath = workingDir + "/" + jacobdllarch;
            File filejacob = new File(jacobdllpath);
            System.setProperty(LibraryLoader.JACOB_DLL_PATH,
                    filejacob.getAbsolutePath());
            AutoItX uploadWindow = new AutoItX();

            String filepath = workingDir + "/home/ionixx/Downloads/123.pdf";
            driver.get(filepath);
            if (uploadWindow.winWaitActive("File Upload", "", 5)) {
                if (uploadWindow.winExists("File Upload")) {
                    uploadWindow.sleep(100);
                    uploadWindow.send(filepath);
                    uploadWindow.controlClick("File Upload", "", "&Open");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
OutPut:-
Only local connections are allowed.
Java HotSpot(TM) 64-Bit Server VM warning: You have loaded library /home/ionixx/workspace/Test/jacob-1.18-x64.dll which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/ionixx/workspace/Test/jacob-1.18-x64.dll: /home/ionixx/workspace/Test/jacob-1.18-x64.dll: invalid ELF header (Possible cause: endianness mismatch)
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
    at java.lang.Runtime.load0(Runtime.java:809)
    at java.lang.System.load(System.java:1086)
    at com.jacob.com.LibraryLoader.loadJacobLibrary(LibraryLoader.java:151)
    at com.jacob.com.JacobObject.<clinit>(JacobObject.java:110)
    at autoitx4java.AutoItX.<init>(AutoItX.java:181)
    at FileUpload.main(FileUpload.java:51)
1Comments
commented by (202 points)
can you post the screenshot of the upload button?

1 Answer

0
0
Usually  unsatisfied link error happens when you are running 32-bit JVM on 64-bit operating system.

Go to uninstall program window and remove any 32-bit JVM.

Check what version of JVM is installed in your PATH variable.

Also, make sure that your IDE is pointing to 64-bit JVM.

After making sure above steps, restart your IDE or the computer to make sure that you are using 64-bit JVM and your IDE is pointing to the same.
answered by (202 points)
10Comments
commented by (12 points)
Am using 64 bit only
[email protected]:~$ java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
[email protected]:~$
commented by (202 points)
Great! Now make sure that your IDE is pointing to 64-bit version. What IDE are you using?
commented by (12 points)
Eclipse Java EE IDE for Web Developers.

Version: Neon.1a Release (4.6.1)
Build id: 20161007-1200
commented by (202 points)
For Eclipse, to see/edit the version being used, go to Preferences -> Java -> Installed JREs.

If you see JDK you want in the list select it
If not, click Search…, navigate the location where your JDK is installed
Now you should see all installed JDKs, select the one you want
Click OK/Finish

You can restart your IDE and see if your JDK is reflected on your project,

Right-click your project > properties
Select “Java Build Path” on left, then “JRE System Library”, click Edit…
Select "Workspace Default JRE"
Click "Installed JREs"
commented by (12 points)
Preferences -> Java -> Installed JREs shows installed library for Name=>java-8-Oracle, Location=>/usr/local/jvm/java-8-oracle, Type=>Standard VM.

Whether i need to change it?
commented by (202 points)
I just realized that JACOB uses native COM library from Windows.

Apart from JDK configuration, we should first make sure that you have all COM components in place.

Can you install wine for Linux? But, I doubt that AutoIT and JACOB will work on  Linux based GUI.
commented by (12 points)
In error shows like "It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'. "

I have tried with following way, but got "not an ELF file" error

> execstack -c /home/ionixx/workspace/Test/lib/jacob.jar
    execstack: "/home/ionixx/workspace/Test/jacob-1.18-x64.dll" is not an ELF file
> execstack -c /home/ionixx/workspace/Test/jacob-1.18-x64.dll
   execstack: "/home/ionixx/workspace/Test/jacob-1.18-x64.dll" is not an ELF file
commented by (202 points)
I looked into below thread and it looks like WINE with JACOB is not possible yet.

https://sourceforge.net/p/jacob-project/discussion/375945/thread/74506e7f/
commented by (202 points)
Yes, those errors you ought to get because there is no compiler for your DLL files on your Linux box.

Try porting the same code on Windows machine
commented by (202 points)
Or you can try exploring Sikuli http://www.sikuli.org/

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...