Modal dialog popup will raise when i click on button , the popup contain only Ok button. - selenium

Modal dialog popup will raise when i click on button , the popup contain only Ok button. I should close the popup by click on ok button .
Exception coming : Exception in thread "main" org.openqa.selenium.UnhandledAlertException: Modal dialog present: First Name should not be blank

try this:
Alert alert = webDriver.switchTo().alert();
alert.accept();

Related

selecting checkboxes in a popup window using selenium webdriver

I have a textbox and a popup window opens on click of this textbox. This popup window contains checkboxes.
I want to click on the above textbox and move the focus to the popup window, select the checkboxes in the popup window and move the focus back to main window.
Image of source code of the popup window is attached in the image tab.
Firefox v33.1
Selenium v2.25
source code
I tried with the below code but it didnt work:
driver.findElement(By.id("FieldView_ctl17_MultiSelect1_InputText")).click();
driver.switchTo().activeElement();
driver.findElements(By.id("checkbox0")).click();
You need to switch on open popup window before finding checkbox as below:-
//First store parent window to switch back
String parentWindow = driver.getWindowHandle();
//Perform the click operation that opens new window
driver.findElement(By.id("FieldView_ctl17_MultiSelect1_InputText")).click();
//Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
if(!winHandle.equals(parentWindow)) {
driver.switchTo().window(winHandle);
}
}
//Now find checkbox and click
driver.findElements(By.id("checkbox0")).click();
//Now close opened popup window
driver.close();
//Switch back to parent window
driver.switchTo().window(parentWindow);
//Continue with parent window

how to keep scroll on modal popup called from an other modal window

here my problem:
I open a modal popup and I can scroll it properly, then when I open a new model popup from this one if I try to scroll down this popup the scroll is on the main webpage in background. How can I focus the scroll on the active modal popup?
thank you

Getting the name of a button while the progress bar is going on in webdriver

I have one button named "Add" in my web portal. On clicking on that button a progress bar appears and the name of the button gets changed to "Adding" from "Add" and remains "Adding" until the progress bar is not moved to 100%. After the progress bar is 100% complete, again the text of Add button changes back to "Add" from "Adding".
I need to assert whether the name of the button is changing from "Add" to "Adding" or not during the progress bar movement. But the problem is once I click on the "Add" button, then use the assertion, selenium will first click on "Add" button, completes the progress bar to 100% and then tries to assertion, but now already the text of "Add" button is already changed back to "Add" from "Adding".
Please give the solution. Thanks in advance.
You can find the element, click and immediately return it's text which can be used later for Assert
public string Test()
{
IWebElement element = Driver.FindElement(By.CssSelector("Something"));
element.Click();
return element.Text;
}
Assert.IsTrue(Test().Contains("Adding"));
Note: C# code

Hide all collapsable divs on 'hamburger' menu click

I have a Bootstrap navbar.
clicking on the hamburger icon will open a menu.
One of the menu item is a button for another collapsable div.
i added this to this button:
$('.nav a').on('click', function(){
$(".navbar-toggle").click()
});
This will close the navbar menu and will show another div.
What i want is clicking on the hamburger icon again will CLOSE the new div and will NOT open the menu.
Basically what is need is the navbar-toggle to close all collapsable div and will open the menu only if there isn't any other div open.
This is my example: http://www.bootply.com/FqZYHFSWrh
Scroll down to get 770px page width
click on login, you will see that the menu disappear.
The next click on the hamburger icon i want to close the login container.
The second click (after the login container is close) i want to open the menu again.
You could add an event handler such as:
$('button.navbar-toggle').on('click', function(event){
if ($('.login-collapse').hasClass('in')) {
event.stopPropagation();
$('.login-collapse').collapse('hide');
}
});

Close a Popup when Tapped

How can I close a Popup when someone Tapped it?
it is possible to set IsLightDismissEnabled to true but it will close the Popup when someone Tap somewhere else rather than the Popup itself.
You can add event handler for Tapped in which you can popup.IsOpen = false;
the purpose of IsLightDismissEnabled is to close popup when it loses focus.