Click on Pop up windows

432 views
Skip to first unread message

Gaurav Kejriwal

unread,
Jul 19, 2012, 3:16:06 AM7/19/12
to webd...@googlegroups.com
Hi All,
Can anybody suggest me how to click on a window pop up.I have tried with the alert thing as well as window handle.
String currentWindowHandle=driver.CurrentWindowHandle
driver.switchto().window(currentWindowHandle)

The Html for my window pop up is like:

<div id="TB_window" style="margin-top: -100px; width: 500px; display: block; margin-left: -250px;" jQuery16408768623524414673="197">
     <div id="TB_title">
         <div id="TB_ajaxWindowTitle">
              Text - Possible Duplicate Transaction
         <div id="TB_closeAjaxWindow">
              <a id="TB_closeWindowButton" href="https://fxonlineindia.riadev.local/Pages/BillPayment/GraphicalTopupTransaction.aspx#" jQuery16408768623524414673="196">
                  <img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px;" src="https://fxonlineindia.riadev.local/img/close.gif" complete="complete"/>


    <div id="TB_ajaxContent" style="width: 470px; height: 155px;">
       <table class="tblCommon" style="margin: 30px auto auto; width: 400px;" cellPadding="6">
            <tbody>
                <tr>
                   <td align="center">
                        <b>
                            Text - There is already a transaction for the same subscriber number and amount. Are you sure you want to continue with this transaction?
                        <br/>
                        <br/>
                        <br/>
                        <div>
                             <input class="button" style="width: 75px;" onkeypress="OnEnterPress(this);" onclick="SaveDuplicateTransactions();" type="button" value="Yes"/>
                             Text - Empty Text Node
                             <input class="button" style="width: 75px;" onkeypress="OnEnterPress(this);" onclick="CloseModal();" type="button" value="No"/>
                             Text - Empty Text Node

I have given this html code just because the window pop up is a ajax window.Please help me to click on the Yes button of the window(marked in red).I am using webdriver with C# .net. 

Thanks & Regards

Gaurav Kumar | GDC-RIA |Euronet GDC Pvt. Ltd

T (Desk)  +91-20-3044 7044

Mobile  +91-9970301751

 


Mike Riley

unread,
Jul 19, 2012, 12:19:34 PM7/19/12
to webd...@googlegroups.com
I see nothing here that is doing an alert (which is a function in JavaScript).  I don't even see anything that shows how this window "appears".  For such things done in HTML you usually see a hidden attribute that keeps it invisible until it is supposed to be displayed, sometimes just the class is what changes.  The only things here with a class setting are your table and the buttons.

If that is all that is happening then there is no "window" to switch to.  You simply have to wait for the elements you want to interact with to be displayed and then treat them as any other page element.

Mike

Peter Gale

unread,
Jul 19, 2012, 12:26:47 PM7/19/12
to webd...@googlegroups.com
>String currentWindowHandle=driver.CurrentWindowHandle
>driver.switchto().window(currentWindowHandle)

Surely if this does anything it would be to switch to the window which is currently active ... so it would be pointless and very difficult to say whether it actually worked or not.


>    <input class="button" style="width: 75px;" onkeypress="OnEnterPress(this);" onclick="SaveDuplicateTransactions();" type="button" value="Yes"/>
> Please help me to click on the Yes button of the window(marked in red).

Treat it as normal, like Mike says ... so doesn't something like this work:

   driver.findElement(Bypath("//input[@value='Yes']).click();

...???



Date: Thu, 19 Jul 2012 09:19:34 -0700
From: lvsk...@cox.net
To: webd...@googlegroups.com
Subject: [webdriver] Re: Click on Pop up windows
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/ii5dZMNJpnYJ.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

Manoj Kapuganti

unread,
Jul 27, 2012, 12:46:31 AM7/27/12
to webd...@googlegroups.com
Hi Gaurav,

Please try with below line moment you get Alert.

driver.switchTo().alert().accept();

Best Regards,
Manoj Kapuganti

Gaurav Kejriwal

unread,
Jul 27, 2012, 1:11:38 AM7/27/12
to webd...@googlegroups.com
Hi Manoj,
I got the solution.It was not an alert or pop up window.It was a simple Html tag.The solution which i applied is:
 driver.FindElement(By.Id("TB_ajaxContent")).FindElement(By.TagName("input")).SendKeys(Keys.Enter);

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/RJ-_pnroSPQJ.

To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.



--

Anand

unread,
Jul 27, 2012, 8:27:04 PM7/27/12
to webd...@googlegroups.com
Although it worked for you, you should really use something like suggested by PeterJef or something which would uniquely find that element like ""
In your case, you are lucky to have 'Yes' as first element which has 'input' tag. If tomorrow, somebody changes the button order then your code will click 'No' instead of 'Yes'. 


Gaurav Kejriwal

unread,
Jul 28, 2012, 4:16:49 AM7/28/12
to webd...@googlegroups.com
Hi Anand,
How can i use the solution suggested by Manoj?It is neither an alert nor a pop up window.So i have to findement by tag name only. 

On Sat, Jul 28, 2012 at 5:57 AM, Anand <anand.d...@gmail.com> wrote:
Although it worked for you, you should really use something like suggested by PeterJef or something which would uniquely find that element like ""
In your case, you are lucky to have 'Yes' as first element which has 'input' tag. If tomorrow, somebody changes the button order then your code will click 'No' instead of 'Yes'. 

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/mjfUg3cYUqQJ.

To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

PeterJef...@hotmail.co.uk

unread,
Jul 28, 2012, 4:43:57 AM7/28/12
to webd...@googlegroups.com

Gaurav

Anand didn't suggest sticking with Manoj's solution, and Manoj only suggest using an alert handler because you wrongly described the page as having a popup window.

Describing it as an Ajax window is also misleading, as Ajax doesn't have anything specifically to do with windows or popups specifically.

Basin your locator the ID of a parent element which a manual user might work for now, but the developers might well feel free to change the structure of the table and/or the naming of the elements becuase such details are hidden from end users so can be changed without change the appearance or functionality of the page, if a change is required for some reason.

The most stable solution is to use an Xpath expression which mimcs the functionality on the screen and the way the user intereacts with it.

So if the action form the user's point of view is to "click on the element on the page which displays 'yes' as its text, then:

    driver.findElement(Bypath("//*[@value='Yes']).click();

... exactly replicates the users action and is likely to be most stable throughout whatever technical changes developers make in the background. They could even change the tag type of display an image for the button and this locator would still work.

Other than using a different attribute to display the value "Yes" on the screen, the only thign that could really breaj this is if the developers put two buttons on the page that both displayed the value "Yes", but then that could be confusing to the user and might well be a bug which you test would highlight, or a change of functionity requiring a change to the action the user takes (e.g. it might now be to click on only a particular one or even both elements that display 'yes').

IMO, replicating what the user does is a much better approach to determining suitable locators than making use of technical details, even ID's, of which the user might not be aware and are not strictly part of the basic requirements or design, just the current (temporary) implementation.



On Saturday, 28 July 2012 09:16:49 UTC+1, Gaurav Kejriwal wrote:
Hi Anand,
How can i use the solution suggested by Manoj?It is neither an alert nor a pop up window.So i have to findement by tag name only. 

On Sat, Jul 28, 2012 at 5:57 AM, Anand <anand.d...@gmail.com> wrote:
Although it worked for you, you should really use something like suggested by PeterJef or something which would uniquely find that element like ""
In your case, you are lucky to have 'Yes' as first element which has 'input' tag. If tomorrow, somebody changes the button order then your code will click 'No' instead of 'Yes'. 


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/mjfUg3cYUqQJ.

To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

Anand

unread,
Jul 29, 2012, 2:13:16 PM7/29/12
to webd...@googlegroups.com
Gaurav, 
I meant exactly what Peter said. I never told you to use Manoj's solution. I just wanted to make you sure that you use some xpath expression or css selector that would uniquely identify the element you want to click so that you do not face problems i future. Peter has already told you how to do that. 
So it might be useful for you to follow the same strategy. 

Gaurav Kejriwal

unread,
Jul 30, 2012, 12:46:21 AM7/30/12
to webd...@googlegroups.com
Thanks  for the suggestion,
Yes the explanation is absolutely right,I just got confused that Anand was suggesting for alert handling.I will try for the xpath solution. 

To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/4FhLdXJYBMEJ.

To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
Reply all
Reply to author
Forward
0 new messages