Has anybody has done this? Navigating to a web page and pop up the save as dialog? In this way, the browser can handle the file type, html, pdf, etc...
Do you need to this to be when a FileHandler is called or on a static webpage?
If it is on a Handler page where the content type is returned then according the latest WatiN release documentation then you can do as follows:
using(IE ie = new IE(someUrlToGoTo))
{
FileDownloadHandler fileDownloadHandler = new FileDownloadHandler(fullFileName);
ie.AddDialogHandler(fileDownloadHandler);
ie.Link("startDownloadLinkId").Click();
fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(15);
fileDownloadHandler.WaitUntilDownloadCompleted(200);
}
Paul
Microsoft.Win32.Registry.ClassesRoot.DeleteSubKeyTree(".pdf");
run this Registry.
Related
I have a C# WinForms application which I need to open a url through it.
The actual task is to display a web page without all it's functionality (changing url/go back button/etc...), do some actions in that site and then retrieve information from it according to what the user entered/did in that site.
Iv'e already tried the WebBrowser option, but it's opening the url site in a browser with all of it's functionality:
System.Windows.Forms.WebBrowser WebBrowser1 = new System.Windows.Forms.WebBrowser();
WebBrowser1.Navigate(new Uri("https://stackoverflow.com/questions/59766190/open-a-url-site-in-a-winforms-window-and-not-from-the-browser"), true);
WebBrowser1.BringToFront();
Any ideas?
Thanx :)
You're passing true as the second argument to the Navigate(Uri url, bool newWindow) method, which specifies that it should open the url in a new window (see the Microsoft documentation).
Changing your code so that it passes false for the newWindow argument will cause the url to be opened in the WebBrowser control instead (you also need to add the control to the form's Controls collection):
System.Windows.Forms.WebBrowser WebBrowser1 = new System.Windows.Forms.WebBrowser();
this.Controls.Add(WebBrowser1);
WebBrowser1.Navigate(new Uri("https://stackoverflow.com/questions/59766190/open-a-url-site-in-a-winforms-window-and-not-from-the-browser"), false);
I'm using a asp.net hyperlink control to open a web URL when a user click the hyperlink.
What I want to do is, say user click the hyperlink, so it should open new tab (not a new window).
if the user clicks the link again, it should not open a different tab. It should redirect user to the same tab which opened last time.
Update: here i found
Popup = window.open(URL, "LoginWindow");
This will redirect user to same window when the link is clicked. I'm using this functionality in popup windows. This works perfectly fine with Chrome & Firefox but not in IE.
It always open a new window rather than redirecting to the already opened one. Any Idea to solve this?
Regards
You can also try target="MyWindow" so it always open in this new window/tab. This way we can avoid opening new window/tab for every anchor link we click on.
The attribute target="_blank" is your only option. Much will depend on users' browser specific settings, you cannot change. In modern browsers this will open a new tab, in others a new window.
After opening in a new tab (new tab vs new window is a browser option, not an HTML option, see Open link in new tab or window) with
target="_blank"
you need to set the hyperlink target to self either when generating your the page in c# or in JavaScript
target="_self"
See http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlink.target.aspx
int i=1;
if(i==1)
{
Hyperlink1.target="_blank";
}
else
{
Hyperlink1.target="_self";
}
Try this code.Hope this will work for you
if (ViewState["hasvalue"].ToString() == "Clicked")
{
HtmlPage.Window.Navigate(new Uri("form2.aspx"), "_self");
}
else // First Time it will be opened in New TAB
{
Hyperlink1.target="_blank";
Hyperlink1.NavigateUrl="form2.aspx";
}
// Assign this value to session
ViewState["hasvalue"] = "Clicked";
}
is there any possible way to check is in webBrowser1 is any jquery dialog active?
here's how looks the dialog which i want to check
i using c# webBrowser class, this is not in a simple html webpage
Have you tried this -
if($(".ui-dialog").is(":visible"))
{
//dialog is open
}
Use this:
$("#mydialog").dialog( "isOpen" )
I use WatiN to automate my testing but how could I handle Web Page dialog window? I can connect to it but can't see source code of it.
Use firebug in Firefox to see the Page Elements/ Dilaog Elements
If you want to handle popup dialog use
ConfirmDialogHandler handler = new ConfirmDialogHandler();
using (new UseDialogOnce(browser.DialogWatcher, handler))
{
browser.Link(Find.ByClass("Your class")).ClickNoWait(); //The action that triggers the dialog
handler.WaitUntilExists(60);
handler.OKButton.Click();
}
i want to know how i can open a browser to a specific web page and then fill out some of the content of the boxes on that page.
My idea is for someone to be able to order a particular item from our internal ordering system. The barcodes for these items are what will populate the fields on the page i want to open.
I no i can open a new instance of ie using Process.Start("IEXPLORE.EXE", url); howver how do i get a handle on that exact ie instance window so i can begin to add the required data to the fields?
Is this even possible?
Thanks very much
WatiN should help with this. I've generally used it for acceptance testing of web apps, but the principle is the same. Open a browser instance, reference stuff in the DOM, manipulate form elements, etc.
In addition to WatiN (as was suggested in another answer), you might consider a load testing package like Web Performance Load Tester. They have a free version that lets you run up to 10 virtual users at a time, which will perform scripted actions.
Another option would be to use a standard WebBrowser object to load your website. The WebBrowser object allows you to access and alter certain web parts. Below is sample code that automatically searches Bing:
private void LoadPage()
{
WebBrowser webBrowser1 = new WebBrowser();
webBrowser1.Navigate("http://www.bing.com");
//Wait for document to load...
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
//Set the text of the search input
HtmlElement txtTextField = webBrowser1.Document.GetElementById("sb_form_q");
txtTextField.InnerText = "My test text";
//Perform a click on the search button
HtmlElement btnSubmit = webBrowser1.Document.GetElementById("sb_form_go");
btnSubmit.InvokeMember("click");
}