Thursday, September 21, 2017
Tuesday, March 21, 2017
Mouse Right Click in selenium
public void MouseRightClick()
{
var driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://en.wikipedia.org/");
IWebElement element = driver.FindElement(By.Id("mp-tfa-h2"));
Actions myaction = new Actions(driver);
myaction.ContextClick(element).Build().Perform();
}
Monday, March 20, 2017
Handle Alert in Selenium
public void HandleAlert()
{
try
{
WebDriverWait _wait1 = new WebDriverWait(webDriver, TimeSpan.FromSeconds(60));
IAlert alertDialog = _wait1.Until<IAlert>(ExpectedConditions.AlertIsPresent());
if (alertDialog != null)
alertDialog.Dismiss();
webDriver.SwitchTo().DefaultContent();
}
catch (UnhandledAlertException)
{
try { webDriver.SwitchTo().Alert().Dismiss(); } catch (NoAlertPresentException) { }
webDriver.SwitchTo().DefaultContent();
}
catch
{
webDriver.SwitchTo().DefaultContent();
}
webDriver.SwitchTo().Frame(StandardConfigFrame);
}
Handling IE Modal Dialogs In Coded UI
try
{
BrowserWindow browserWindow = new BrowserWindow();
browserWindow.PerformDialogAction(BrowserDialogAction.Ok);
}
catch (Exception)
{
// If a popup does not exists and an error is thrown, continue...
Playback.PlaybackSettings.ContinueOnError = true;
}
=======================
//Launch browser BrowserWindow browser = BrowserWindow.Launch("C:\\Users\\v-zuqu......"); //Create Control for Hyperlink that u want to click.. UITestControl control = new UITestControl(browser); control.TechnologyName = "Web";//u can see technology name in search properties window by spying on Hypelink using CodedUITest Builder control.SearchProperties.Add("Id","xxxx","ControlType","Hyperlink"....);//u can see the search properties by spying on the control //Wait for the above control after launching the browser control.WaitForControlReady(); //Now, click on that Control Mouse.Click(control); //you u will get IE pop-up..so..create IE pop-up control UITestControl popup = new UITestControl(null); popup.TechnologyName = "MSAA"; popup.SearchProperties.Add("Name","xxxxx","ClassName","xxxxx"......);//u can add more search properties by looking at Search properties window. //u need to click on yes button..so, create control for that..as... UITestControl yesBtn = new UITestControl(popup); yesBtn.TechnologyName = "MSAA"; yesBtn.SearchProperties.Add("Class","xxxx","Name","xxxx"....);//add search properties by looking at Search properties window //Click on yes button, if ur unable to click on yes button first write "popup.SetFocus();" and then click on yes button Mouse.Click(yesBtn); //Now close thebrowser using the following code. browser.Close();
Search Configurations for the control in CodedUI
Search configuration of the control
We have some predefined search configuration which helps to narrow down the search space (search only in visible controls) or to do perform some prerequisite before actually starting the search (expand parent tree node before searching for the child node). Following are the different search configs:
var app = ApplicationUnderTest.Launch(@"yourapplication.exe");
var mainWindow = new WinWindow(app);
mainWindow.WindowTitles.Add("Form1");
WinText textLabel = new WinText(mainWindow);
textLabel.SearchProperties.Add(WinControl.PropertyNames.Name, "Some Text Label");
WinEdit siblingEditControl = new WinEdit(textLabel);
siblingEditControl.SearchConfigurations.Add(SearchConfiguration.NextSibling);
siblingEditControl.Text = "setting the text";
SearchConfig Parameter | Description |
AlwaysSearch | UITest uses a cache while doing actions on an Application by adding Always Search in the search config user can force UITest to not to use the cached value for the control. |
DisambiguateSearch | If the parent and the controls properties are same there are chances that UITest would start doing action on the parent itself. This config can be used to ask the playback to act on its child rather than the parent itself. |
ExpandWhileSearching | Expand the control before looking for the other control inside it. E.g., TreeView |
NextSibling | Search in the siblings inside the container. Sometime if the control is nameless we may iterate from the named control inside the same container to reach the control. |
VisibleOnly | Search only in the visible control. It helps to reduce the search space. |
Subscribe to:
Posts (Atom)