Watin AttachTo popup window - testing

We are using Watin to automate the website testing and try to implement the following: Click on a button to bring up popup, click on the Generate button on the popup window to generate file. We wasnt able to get the popup window using watin. ERROR: "Could not find an IE window matching constraint: Attribute 'href' matches 'Regenerate'. Search expired after '30' seconds." Please give a hint on what has gone wrong. Your help would be much appreciated.
The code snippet as below:
ieInstance.Button(Find.ByName(Button1)).Click();
ieInstance.WaitForComplete();
var popupUrl = new Regex("Regenerate");
//part of popup URL: "RegenerateDialog.aspx?Type="
var popupBrowser = Browser.AttachTo<IE>(Find.ByUrl(popupUrl));
if (popupBrowser != null)
popupBrowser.Button(Find.ById("RegenerateDialogBtn")).Click();
The popup window code as below:
function ShowEXPFileWindow(Type)
{
//do some stuff
var oWnd = window.radopen("RegenerateDialog.aspx?Type=" + Type, "RegenerateDialog");
oWnd.set_title("");
oWnd.center();
}
HTML to bring up popup window:
<td><input type="submit" name="ctl00$Body$ConfigRadGrid" value="Regenerate" onclick="ShowEXPFileWindow('OD'); return false;" class="submit" /></td>

Instead of
ieInstance.Button(Find.ByName(Button1)).Click(), use
ieInstance.Button(Find.ByName(Button1)).ClickNoWait()
and check. Is it possible to post the image of the pop-up window? or when you click on button, which control is selected by default? If it is 'Regenerate' then try to press 'Enter' Key and check.
Is the pop window is another IE window? If yes, then attach it using
Find.ByUrl(url => url.Contains(expectedURL))

Related

Clicking button with selenium doesn't throw exception but the button isn't actually clicking?

I am trying to click a button, which once clicked some text should appear. Selenium is not throwing any errors which means the buttons should have been clicked however the text is not appearing (it works manually).
<button class = "redButton one">
<img src = "images/name.png" class = redImage">
"Name"
</button>
I tried to click the button with the xpath: "//button[contains(text(), 'Name')]". I don't understand why the text is not appearing.
What is the expected text to be displayed after button click event? In order to help with this request, provide the HTML snippet of <button> before & after click event. Since this is working fine manually, did you try adding adequate wait time for the text to display?

cypress how to test data-state is visble

Here is the scenario:
I click a button and a popup comes and I want to test when I click on button, the popup should be visible
Sample code:
<button id='bt'>
<div id ='new_div' data-state = visible >
cy.get('#bt').click()
//after clicking this I need to test data-state of "new_div" is visible/not
cy.get('#new_div').should('have.data-state','visible') //something like this
You can do this:
cy.get('[data-state = visible]').should('be.exist')
It will basically check if this tag data-state = visible present or exist inside your DOM at the moment when the popup is visible.
But the best way, of course, is to grab selector from the opened popup!

How to force onClick event with Selenium?

I am testing an application that have the following html code:
...
<input
type="button"
class="picto modif"
onclick="hideDiv('divGlobalResult');showDiv('divForm')"
/>
When the user clicks on this button, the div divGlobalResult is hidden and the div divForm is shown.
I want to simulate this action with Selenium. Here is how I did:
focus css=input.picto.modif
fireEvent css=input.picto.modif click
However, the divForm appears while the second div divGlobalResult stays on the screen...
What am I missing?
function hideDiv(idDivElement) {
$("#" + idDivElement).css("display", "none");
}
function showDiv(idDivElement) {
$("#" + idDivElement).css("display", "");
}
thats happening because Selenium click function cannot simulate a real "Click" action performed with the mouse.
I have also faced this problem and the solution that best suited me was to take control of the mouse by using java robot and performing the click with it.
I hope this helps.

Click on hyper link is not loading webpage using Selenium webdriver

Here is how my html looks like on the web page:
<form id ="invoice request">
<div id = "charges">
<div id = "charges">
<div id= "billing">
<a id = "modify" class="modify_link" href = "#"> Modify </a>
I am unable to load Web page by clicking on Modify charges link. Selenium test passes without actually loading webpage.
Here are my trails:
driver.findElement (By.id ("modify")).click ();
wait.until (ExpectedConditions.presenceOfElementLocated (By.id ("modify")).click ();
What's wrong in the code?
You're expected condition doesn't actually do anything there. You're HTML shows that the element is already present when you click, because it's what you clicked. That element will still be on the DOM. You need to find an element (on what I am assuming is an AJAX call) that is presented only after you have clicked the modify button to ensure that the click button you invoked did anything.

Unable to select IE8 popup window using selenium RC

I am trying to send commands to a popup window in IE8 with Selenium RC.
Currently, I am able to click on a button and open the popup window.
However, I am unable to select the window to send commands.
I have done extensive research on this subject for about a week and I believe this is strictly an IE issue. I have found some work-arounds; several blogs have instructed users to open up a blank window to "catch" the commands.
However, when I implement the code below, a blank window pops up and upon clicking the button that opens the pop up, a THIRD window opens and loads with the page I need.
Am I setting the target inaccurately? Please see below for selenium rc commands as well as the html source code of the page.
Java Code
selenium.runScript("selenium.browserbot.document.getElementByID(
'ctl00_ContentPlaceHolder1_WebGroupBox1_btnAddRequirement').target='popup'"
);
selenium.openWindow("", "popup");
///Click on Add Requirement button
selenium.click("id=ctl00_ContentPlaceHolder1_WebGroupBox1_btnAddRequirement");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
selenium.selectWindow("popup");
HTML for Add Requirement button
<input id="ctl00_ContentPlaceHolder1_WebGroupBox1_btnAddRequirement"
type="submit"
style="font-family:Arial,Times New Roman,Courier New;"
onclick="return validateProject();
WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions(
"ctl00$ContentPlaceHolder1$WebGroupBox1$btnAddRequirement",
"",
true,
"",
"",
false,
false
)
)
"
value="Add New Requirement"
name="ctl00$ContentPlaceHolder1$WebGroupBox1$btnAddRequirement"
>
In WatiN (different I know), I had to send a combination of alt+tab and enter to deal with pop-up boxes.