Handle a popup in selenium webdriver using c# - c#

When I click on a button on a page, a popup is displayed. This is not a windows popup. It is the application popup.. The popup I get in my application is similar to the one i have shown in the image with a X button. now How do I move the driver control to the popup and then click on the close button available on the popup and then move back my control back to the original page..
I have to do this using Selenium WebDriver and C#.

You need to do the following...
Loop through the windows and find the desired window
Switch to the windows
Find the button in the current window and click the same
Here is the sample code in C#
foreach (string handle in browser.WindowHandles)
{
IWebDriver popup = driver.SwitchTo().Window(handle);
if (popup.Title.Contains("popup title"))
{
break;
}
}
IWebElement closeButton = driver.FindElement(By.Id("closeButton"));
closeButton.Click();

The new pop message too have an id or class name..
First get the class name or id of that pop up and the go for the xpath(may be we will find class name) of the close button and click on it.

The example you have shown is not a popup, but a simple DHTML window.
To access the X of the example you have provided, you could use: driver.findElementBy(By.id("profile-tooltip-closebtn")).click().

You can try
driver.switchTo().frame(0);

Related

How i can set the Searchbar Inative and User click on this for open a Dialog

My Question is how can i Build in Android C# an SreachView this is off by but Show and any User click on this a Dialog open and asked the User to give her ok.
I work in a Fragment
SearchView searchView;
searchView = (SearchView)View.FindViewById(Resource.Id.MenuSearchitem);
searchView.ClearFocus();
searchView.SetOnQueryTextListener(this);
searchView.SetOnQueryTextFocusChangeListener(this);
searchView.SetIconifiedByDefault(false);
searchView.SubmitButtonEnabled = true;
searchView.QueryHint = mapViewModel.AddressPlaceholder;
thats all fine, but nothing work for click on the searchbar and no dialog is open.
follow ways i have used IOnFocusChangeListener and IOnSuggestionListener dont gave the right way for me
you can use onTouchListner, wherever you will touch on the screen the touch event will be triggered, there you can check which widget is clicked just check it and open dialog in it.

disable any click on elements from the MainPage when a PopUp is launched

I want to display a PopUp in my C# universal app like this :
but the problem,is that my PopUp deosn't work like this Frame that appears in the Groove App,per example,what I want is when I click on a button in the MainPage, it displays the PopUp then to disable the click on any element in the MainPage,the focus will be only on the elements of the Popup until the close of this PopUp
is this possible??
thanks for help
What you want is a modal window, for example you can create one with Content dialog.
ContentDialog modalWindow = new ContentDialog()
{
Title = "youTitle",
Content = "Content",
PrimaryButtonText = "
};
await modalWindow.ShowAsync();
You can show more here
Actually, the "PopUp" you've seen in the Groove App is not a Popup. It's a AccountsSettingsPane. This class provides methods to show the accounts pane and also to enable the app to register callbacks when the accounts flyout is about to be displayed. For more information, please refer to the official Web account management sample in GitHub and especially the Single Microsoft Account scenario in this sample.
When using AccountsSettingsPane, if we use the ProcessMonitor to track this UI, we will find that it is a system app C:\Windows\SystemApps\Microsoft.AccountsControl_cw5n1h2txyewy. What happened here is similar to this case: UWP Modal Window. So you can refer to Launch an app for results to implement this behavior. But this requires you to create another app.
For ContentDialog, it can not be movable. If your content is not complex, you can try with MessageDialog class. This dialog is movable. For more info, please refer to Message dialog sample.

Use WatiN in windows Form to Automate Clicking and Writing in Internet Explorer C#

Internet Explorer is open and it is showing a webpage. We know there a drop down and a textbox and a button are exist in this page.
I need to select an item from drop down, writing a text in textBox and clicking on that button.
How Can I do these using WatiN by pressing on a button in windows form, I currently add its related libraries and I have add WatiN.Core in using section, but it seems it is not working with windows forms.
This is a very small example but not sure what you mean by "not working" (does it throw an exception, are you able to start the program, when you click the button it fails, you need to be more precise on this).
using(var ie = new IE){
ie.GoTo("http://www.yourwebpage.com");
TextField entry = ie.TextField(Find.ById("myEntryBox"));
Button btn = ie.Button(Find.ById("submit"));
SelectList menu = ie.SelectList(Find.ById("selectList"));
entry.Value ="Hello world");
menu.SelectByValue("2");
btn.Click();
}
if you are having other problems, please, let us know.

Issue with WatiN and IE9 regarding multiple dialogs

I am using the latest 4/12/2011 build of WatiN (2.1.0.1196).
I have an aspx page loaded into an IFrame in Dynamics Crm. There is a button on the page that opens and modal dialog form. So far most of the test cases are working correctly with WatiN except for a specific use case.
If a specific combination of controls are set on the modal dialog, a confirm dialog box will pop up after the user presses the submit button. If the user selects ok it will continue the submit execution, if cancel it will return back to the modal dialog. The test times out when this confirm dialog box appears. I cant seem to get the handler setup right to catch the confirm dialog.
Here is a test method I have been trying:
[TestMethod]
public void Add_New_Post_To_Record_Public_NotOnBehalf_NoSub_No_Notifications()
{
using (var browser = new IE("URL to the IFRAME"))
{
var approveConfirmDialog = ReturnDialogHandler.CreateInstance();
var confirmCode = Guid.NewGuid();
//logon to CRM
logonToADFS(browser);
var recordPage = browser.Page<DiscussionRecordpage>();
recordPage.CreateNewPostButton.ClickNoWait();
HtmlDialog dialog = browser.HtmlDialog(Find.ByTitle("New Post"));
var messageText = dialog.TextField(Find.ByClass("required"));
messageText.TypeText("Type some text. Confirmation code: " + confirmCode.ToString());
var button = dialog.Button(Find.ByClass("submit-button"));
using (new UseDialogOnce(browser.DialogWatcher, approveConfirmDialog))
{
button.ClickNoWait();
approveConfirmDialog.WaitUntilExists();
approveConfirmDialog.OKButton.Click();
}
browser.WaitForComplete();
Assert.IsTrue(browser.ContainsText(confirmCode.ToString()));
}
}
I have tried a couple different variations all with the same result. I assume that I need to use the ReturnDialogHanlder.CreateInstance() method for IE9 compatibility, but the standard ConfirmDialogHandler did not seem to work either. Honestly, I don’t know if I am using the dialog handler correctly in this case, but I can click the ok buttons on other confirm dialogs that spawn from buttons on other pages. This is a bit unique since it is spawning from a modal dialog instead of a page.
I also tried using this custom handler (C# WatiN - Add an AlertDialogHandler to click ok button on every Alert dialog window) with no results.
Thanks in advance.
It's too hard. I suggest a workaround: most of the case, you could close the dialog using keyboard. so you could sendkeys to close the dialog. Just FYI.

WatiN pressTab doesn't press tab

Has anyone found a means to press tab with watiN in Internet explorer?
Do you mean you want to press the tab key itself, or just click on an HTML element that looks like a tab? For the latter use the Click method against the appropriate element (Div, Span etc). Otherwise you could try SendKeys instead of PressTab. e.g.:
IE ie = new IE("http://www.google.com");
ie.AutoClose = false;
ie.TextField(Find.ByName("q")).Click();
SendKeys.SendWait("{TAB}");
The above example will set the focus the text field then tab off, putting focus on the search button.
we had the same problem, we resolve it focusin on the browser and using SendMessage (Win) to the specific hwnd.

Categories