我是自动化的过程,一个过程,我需要下载csv文件从一个网站。
我已经为此编写了jquery代码。有人能告诉我如何将这个代码与我的Java selenium代码集成起来吗?
a.java
package package1;
import java.text.ParseException;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.seleniumhq.jetty9.util.log.Log;
public class Noofrowsandcols {
public static void main(String[] args) throws ParseException, InterruptedException {
WebDriver wd;
String exepath="C:\\Users\\sh370472\\Downloads\\chromedriver_win32 (2)\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", exepath);
wd= new ChromeDriver();
wd.get("https://www.shipper-ml.com");
wd.findElement(By.id("inpUserId")).sendKeys("xxxxxxxx");
wd.findElement(By.id("inpPassword")).sendKeys("xxxxxxxxxxxxxx");
wd.findElement(By.id("btnLogonLabel")).click();
Thread.sleep(1000);
wd.get("https://www.shipper-ml.com/viewReports.do");
}
}
b.js
$(document).ready(function () {
$(window).load(function () {
$('.ibody tr').each(function (a, b) {
var count=0;
var name = $('.cl', b).text();
if(name.indexOf(".CSV")!==-1 && name.indexOf("TAS")!==-1){
var d= a-9;
var hiddenIFrameID = 'hiddenDownloader' + count++;
var iframe = window.createElement('iframe');
iframe.id = hiddenIFrameID;
iframe.style.display = 'none';
window.body.appendChild(iframe);
iframe.src = "https://www.shipper-ml.com/viewReports.do?
ctrl=reportListForDownload&action=DownloadReport¶m="+d;
}
});
});
JavascriptExecutor js = (JavascriptExecutor) wd;
js.executeScript("$(document).ready(function () {
$(window).load(function () {
$('.ibody tr').each(function (a, b) {
var count=0;
var name = $('.cl', b).text();
if(name.indexOf(".CSV")!==-1 && name.indexOf("TAS")!==-1){
var d= a-9;
var hiddenIFrameID = 'hiddenDownloader' + count++;
var iframe = window.createElement('iframe');
iframe.id = hiddenIFrameID;
iframe.style.display = 'none';
window.body.appendChild(iframe);
iframe.src = "https://www.shipper-ml.com/viewReports.do?ctrl=reportListForDownload&action=DownloadReport¶m="+d;
}
});
});
};“));
https://sqa.stackexchange.com/questions/36585
复制相似问题