WatiN: automate Web Page dialog - c#

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();
}

Related

Open a url site in a WinForms window and not from the browser

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);

Redirect webpage to same tab in asp.net

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";
}

webBrowser check is jquery dialog box is active

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" )

open new window without the browser giving warning that is a popup

I am working on mvc2 and i'm trying to open from javascript in a new window something.
if i only use inside the js function window.open("action/action/"+param) like this
function(){
window.open("action/action/"+param);
}
it works perfectly and the browser does not warn me that it is a new popup that i'm opening.
But if i make an ajax call before the window.open, the browser tells me that is a new popup and if i accept it.
if (json.data && json.data.URL)
{
window.open("action/action/"+param);//opens in a new window only if i accept popups
}
how can i make it work without the browser considering it as popup?
You can't popup a window "randomly" it needs to be right after the user has clicked something or did an action so that the browser doesn't think it's a random ad popup.
The window has to open as a direct result of the user's input. For example, you could open a new window inside a click handler. It's not full proof by any means, but it's one measure the browser can take to try and prevent unwanted popups.

Show IE "Save As" dialog using Watin

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.

Categories