我使用 Jacob Api在使用selenium自动化Web应用程序时上传文件,但它会产生UnsatisfiedLinkError。我是Jacob api的新文件上传所以请提前帮助和感谢。
示例脚本: -
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@test.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();
}
}
}
输出: -
Starting ChromeDriver 2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3) on port 6511
Only local connections are allowed.
Oct 09, 2017 10:56:14 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Oct 09, 2017 10:56:15 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
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)
是硒自动化的新手,所以请提前帮助和感谢。
答案 0 :(得分:0)
在我弄清楚这一点之前,我度过了一段非常艰难的时期。祝你好运!
您需要将Jacob dll文件复制到System32文件夹(或SysWOW64文件夹 - 取决于您使用x86与x64的JRE / JDK类型)。
Copy these dll files:
jacob-1.18-x86.dll
jacob-1.18-x64.dll
然后,
paste them in System32 folder:
C:\Windows\System32
If it still doesn't work copy the dll files to:
C:\Windows\SysWOW64