I having problem making a file download work when pushing a <a> with Puppeteer-sharp in headless mode.
I have this kind of html:
<div>
<button>Button</button>
</div>
In headless mode = FALSE, everything is working, pushing the anchor tack download the file to the browser download folder, and pushing the tag is also working.
but if I switch the mode to headless = TRUE, then the file is not downloaded, I very sure that puppeteer are clicking the tag as I get no error running the code. The button click is working. I tried search all my c-drive but I cannot find the file that is supposed to be downloaded anywhere. I tried taking some jpg dumps and all seams to work.
Any help on how to make it possible for Puppeteer-sharp to work in headless mode and still be able to download files when clicking a link?
I found a solution:
Adding this to the IPage object:
await page.Client.SendAsync("Page.setDownloadBehavior", new
{
behavior = "allow",
downloadPath = Path
});
made the file download also in headless mode.
Related
I would like to know to know how to download HTML code from a webpage in Xamarin. The webpage is opened on a Android device and requires login, therefore it cannot be downloaded using a url link in WebClient. I am interested if the is a possibilty to download the HTML code from the opened webside, so that it can be used to notify me about changes in the webside.
My code to open the webside (then i need to log in):
void WebViewFunction()
{
webView1 = FindViewById<WebView>(Resource.Id.webView1);
webView1.Settings.JavaScriptEnabled = true;
webView1.SetWebViewClient(new Client());
webView1.LoadUrl($"https://www.strava.cz/Strava/Stravnik/Prihlaseni");
}
I have absolutely no idea how to do it since I am a beginner.
Thanks for your answer.
I have a test which uploads a profile image to the web application. In order to upload the image file, an upload button is clicked which opens a file upload window as shown in the screenshot below.
The test then sends keys of the image file path to the file upload window in order to upload the file. When the test is run in chrome headless mode, the file upload window is not found and the send keys step fails.
If the test is run in normal mode (without headless option) the test runs fine without any issue. What could be the problem? Is there any way to fix this? Following code is used to set focus and send keys to the browser file upload window.
var dialogHWnd = FindWindow("#32770", "Open"); // Title for modal. IE: "Choose File to Upload"
var setFocus = SetForegroundWindow(dialogHWnd);
SendKeys.SendWait(#picPath);
Thread.Sleep(5000); //wait
SendKeys.SendWait(#"{Enter}");
Reporter.LogTestStepForBugLogger(Status.Info, $"Sent keys {picPath} and Enter to upload the Profile Picture.");
With selenium, you can just sent the full path of the image to the input element that is responsible for the upload.
Check the html code and search for relevant probably with "hidden" attribute or something common for this upload section.
Then just use:
driver.findElement(by.xpath('input xpath or id ..').sendKeys('path of the image in your system');
When you type javascript:window.open('http://stackoverflow.com') in chrome's navigation bar, it opens new tab. I want same, but when running chrome from cmd:
var process = Process.Start("chrome.exe",
"javascript:window.open('http://stackoverflow.com')");
I'm doing this because I want to close that window later from inside it with window.close(). If I open website directly, error is thrown:
Scripts may close only the windows that were opened by it.
If you just want chrome to open a new tab to a page, why not try:
var process = Process.Start("chrome.exe", "http://stackoverflow.com");
If you just want to close the window later with JS, what about:
window.open(location, '_self', '');
window.close();
Note, you cannot automatically add the javascript prefix to a chrome URL, even with copy and paste - this is a security feature.
see - Javascript stripped from URL bar?
I am using a WinForm webbrowser, i load an local html file which contains and flash player that plays a video but the problem is that the player works but the video is not loaded.
When i open the html file in a browser it works fine.
Here is the code i am using:
string curDir = Directory.GetCurrentDirectory();
this.webBrowser1.Url = new Uri(String.Format("file:///{0}/Resources/streaming.html", curDir));
The file location is correct, is there anything i can do to solve the problem ?
Try explicitly disabling the following Browser Features for your WebBrowser-based app: FEATURE_LOCALMACHINE_LOCKDOWN, FEATURE_BLOCK_LMZ_OBJECT, FEATURE_BLOCK_LMZ_SCRIPT. You could reuse some code from here.
I have a file that I can get to with the UNC \mypath\myfile. I retrieve the path with c# and assign it to a link. The browser opens the file inside itself (ie display in the browser) without problem. But, when I try and save to \mypath\myfile I am prompted to save it locally. If I view the file outside of the browser (IE 7) I can edit and save as expected, again, via the UNC.
What I trying to do is use iframe to display the file from my UNC (file:///\mypath\myfile), which does work, but now I can't edit it. Outside the browser I can.
Is there anyway to save a PDF when displaying it inside the browser? I also tried a button to use the save method on the pdf, but it did not work.
Thank you.
I am using IE 7 and Adobe Professional 7.1.0.
When you open a file via a web browser the web browser downloads the file locally, then sends a local file path to the application that opens it. Even in the case you are using a UNC in your href Adobe does not get that UNC path to save back to, it is getting a local machine path. Keep in mind the browser does the same thing even if the UNC is a local machine path.
I don't think that the behavior you want is possible.
<body>
<div style="height:80px">
<p>Save
</div>
<div>
<iframe width="100%" height="100%" src="pdfname.pdf" />
</div>
</body>
On downloadpdf.aspx's page load event,add:
Response.AddHeader("content-disposition","attachment; filename=pdfname.pdf")
Response.ContentType = "application/pdf"
Server.Transfer("pdfname.pdf")
Untested, but should give you an idea...
Saving a PDF in your browser (through File-Save As in IE etc) or Save A Copy in the Adobe system will always prompt you to save it locally. You could navigate manually to your UNC path, but this is browser behaviour, not server behaviour.