我在android webview中打开一个网页。填写网页上的信息后,有一个下载文件的按钮。但该文件未下载。关于哪个url传递给下载任务我感到困惑。按钮上的按钮应下载pdf文件。但它没有做任何事情
mWebView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.allowScanningByMediaScanner();
request.setMimeType(mimetype);
//------------------------COOKIE!!------------------------
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,URLUtil.guessFileName(url, contentDisposition, mimetype));
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
DownloadManager dm = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
}
});
答案 0 :(得分:0)
你试过这个吗?
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using System.Threading;
namespace SeleniumTests
{
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
public class TestWithMultipleBrowsers<TWebDriver> where TWebDriver : IWebDriver, new()
{
private IWebDriver driver;
[SetUp]
public void CreateDriver () {
this.driver = new TWebDriver();
}
[Test]
public void GoogleTest() {
driver.Navigate().GoToUrl("http://www.google.com/");
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("Bread" + Keys.Enter);
Thread.Sleep(2000);
Assert.AreEqual("bread - Google Search", driver.Title);
driver.Quit();
}
}
}
});