how can i handle rad window popup by watir script? - watir

How can i handle this type of Rad window pop up by using watir.
<span id="RadWindowTitlectl00_ContentPlaceHolder1_rwmWinManager_rwMessage" class="RadWTitleText" onselectstart="return false;" unselectable="on">Check Results</span>
This is for button html...
<input id="btnOk" class="LoginButton" type="button" onclick="javascript:CallBackToEdit('1');" value="Ok">
Please give guidance for this.

Need more info to help you.
If you're trying to access a newly generated popup window, do it something like this:
browser.window(:title => "annoying popup").use do
browser.button(:id => "close").click
end

Given that the HTML you have supplied just seems to be an ordinary div element, my first guess is that this is not truly any kind of popup, but just a div that is using Ajax/javascript and CSS to simulate the effect of a popup (by manipulating the coloring of objects, and perhaps the 'enabled' state as well so it appears to be modal)
To be sure we'd need to see more than just fragments of the HTML Or better yet a reference to an example of a page that implements this control. It would also be helpful to know WHICH set of 'Rad' controls (since Telerik has multiple versions (Ajax, MS-MVC, Silverlight, WPF and Winforms) available) and knowing which one might make it easier to find an example of the control on the demo pages at Telerik's site
based on what little you've provided I would think that simply
browser.button(:id, 'btnOK').click #ought to work
Note that since this thing could well be coming into existence via client side scripting, potentially a brief wait might be necessary to ensure that the object exists, before trying to click it.
If that does not work for you, then use developer tools to look at the button input element and make sure it is not in a frame.
Otherwise please give us either more HTML, specifics on which RAD control this is (so we can perhaps find an example among their demos) or both.

Related

How do I declaratively push BottomSheet with Navigator 2.0?

I'm new to Navigator 2.0 in Flutter, and now I'm trying to achieve BottomSheet behavior using declarative approach. Unfortunately, I only managed to come up with quite a cumbersome way to do that so I'm wondering if there's an easier way.
I'm building a shopping app and I want to show the item details card that slides out from the bottom of the screen, dimming the previous page (as shown in picture), when user taps on item in a list. I also want to allow url support, so that /item/id opens home page and then shows the details card over it.
So how I think this could be done is to push (or to add to Navigator's pages array in case of Navigator 2.0) custom non-opaque page with no transition animation using TransitionDelegate and PageRouteBuilder, and then animate dimming and sliding by hand using animation controllers. But this approach seems unnatural (and genuinely scares me to be honest) and it's still not clear to me how to handle back button in this case (Do I need to somehow notify the page to play closing animation from Navigator's onPopPage, is this the way to do this?).
If anyone has an experience of implementing similar feature, I would really appreciate sharing it! Or maybe you have come up with more elegant solution, then tell me about it and I'll give it a try! Thanks!

Add items to browser context menu?

I have a page in which an augmented context menu would be natural and intuitive for a visitor. Not so different from a ton of pages, I'm sure. EDIT: Of course, I must do that without losing any of the browser's native context-menu items/actions. Just want to add an item.
Is there any way to accomplish that yet in any browser?
We can imagine (putative) markup for such a thing. Maybe somehting like:
<context n onclick="handleNewItem"> my new item </context>
where n is the line number of "my new item"
Thanks!
You could totally replace the context menu with your own, but then you'd loose the standard browser's one.
Unless you are writing a browser extension, I don't know of any way to just append commands to the browser's context menu from within javascript.

How to click a strange link looks like button in watir

I want to use the Watir to click a link that looks like a button attached the image.
I use the following method,but doesn't works:
#browser.div(:id,"NetworkAnalysisTabPanel").div(:index,1).div(:index,1).ul(:index,1).li(:index,1).link(:index,2).click
Note:
#browser.div(:id,"NetworkAnalysisTabPanel").div(:index,1).div(:index,1).ul(:index,1).li(:index,1).link(:index,2).flash
is working fine but click is not working in IE and FF
Link looks like this:
And HMTL like this:
Note: I am able to click on the element using selenium IDE with clickAt method
Try this (not tested):
browser.link(:class => "x-tab-strip-menu").click
If you can flash the link, but click does not do what you want, see this: How to find out which JavaScript events fired?
FYI what you have are links that are using standard background images controlled via CSS magic that keys on the class of the link to know what background to set. That's where the image comes from, and why you don't see it as part of the link in the HTML.
In that control, each tab is a list item element (li) in an unordered list (ul), and each list item has an ID, so that's the easiest way to tell it which tab you are trying to click inside.
Try identifying things starting with the LI that is the tab container, as within that container there is only one instance of each link of a given class. Of the 4 links, only one is without any kind of easy identifier, and if you need to click that one you'd need to use :index, but for the other 3 links using :class ought to work. This should result in code that is less brittle and subject to being broken if the order of tabs changes, or the page is refactored.
#browser.li(:id,"NetworkAnalysisTabPanel__ext-comp-1038").link(:class, "x-tab-strip-menu").click
If the number at the end of the ID is subject to change, you can try a regular expression to match the part you can predict and is unique from the others
#browser.li(:id,/NetworkAnalysisTabPanel__ext-comp-/).link(:class, "x-tab-strip-menu").click
If you can reliably identify the object and use .flash but .click does not seem to do anything, you may have to use .fire_event('onclick') instead or .click.
#browser.li(:id,/NetworkAnalysisTabPanel__ext-comp-/).link(:class, "x-tab-strip-menu").fire_event('onclick')
If that does not work, then you need to start experimenting with likely events that the control might be looking for (which will not necessarily show up in the HTML btw.. it may be in javascript or CSS etc)
UPDATE
This is where having an live example of the control that we can interact with is critical. doing some googling on the class names I was able to find one here and that let me play with it a little, and what I discovered is that it is looking for onmousedown. so, on that site, this works
browser.li(:id, 'TabPanel1__ctl07').link(:class, 'x-tab-strip-menu').fire_event('onmousedown')
Now since those ID's may not be the best identifier, a bit more digging (using .text on the li that holds the tab parts) found me some text, which in a menu like that ought to be unique.. SO, we can change this to make things a bit more robust and clearer as to what tab I'm clicking on (this will also be less subject to breaking if the tabs change around.
browser.li(:text, 'Menu 1').link(:class, 'x-tab-strip-menu').fire_event('onmousedown')
Lastly, since the click is causing client side code to execute, you may need a brief pause (a one or two second sleep) to wait for that portion of the page to re-render etc.

Adapting Modal Dialog Script to Firefox

I'm adapting my regression tests to test a web app in firefox. The biggest stumbling block seems to be how to automate the modal dialogs in firefox.
In ie I use variations of the script below, but it doesn't work in Firefox. Is there an alternative that will work in both ie and firefox?
popup=Thread.new {
autoit=WIN32OLE.new('AutoItX3.Control')
ret=autoit.WinWait(title,"",60)
if (ret==1)
puts "There is popup."
autoit.WinActivate(title)
button.downcase!
if button.eql?("ok") || button.eql?("yes") || button.eql?("continue")
autoit.Send("{Enter}")
else
autoit.Send("{tab}")
autoit.Send("{Enter}")
end
elsif (ret==0)
puts "No popup, please check your code."
end
}
at_exit { Thread.kill(popup) }
end
button.click_no_wait
check_for_popups("Message from webpage", "OK")
Given you are talking about a javascript created dialog, I really have to ask, is there a lot of value in actually testing those?
It basically amounts to testing the functionality of the browser
If you are talking about the type of popups described here http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups then I think the first solution, of overriding the javascript may well be your best cross platform option.
The problem with modal dialogs like this is that they are basically a UI even that is happening out at the OS level, it's no longer inside the browser DOM, and thus you need tools that are specific to the OS (like stuff that depends on win32ole, such as autoit) in order to generate the necessary interaction with the native UI and click buttons, send keystrokes etc. Most of the solutions presented should I think work with FF on windows (with proper renaming of expected window titles etc) but would fail on a mac or *nix OS. That means you need a different solution for each OS, which is a pain.
It might simply be easier to verify you can find the proper stuff that would fire the event in the HTML of the page, so you know an event WOULD be fired, and then override things so it isn't. After all it's not really your job to validate that the browser pops up a local dialog when something like alert('This is an alert box') is invoked in javascript. Your concern is that in the HTML a given element is coded to fire off the event that is needed e.g. that there's something like this onClick = 'javascript:x = confirm('Do you really want to do this');" affiliated with the element
I am experiencing a similar problem in Firefox (and I do have to test in Firefox). I can see the code calling the Javascript but when I try to override as described above nothing happens. Is there any kind of a workaround for this? Anticipated updates to Watir? ;-)

How to control over browser back button

I want a confirmation window on click of a browser back button. If I press yes then the previous page will get load ortherwise I will remain in the same page?
Any suggestion is highly appreciated.. But please be on track.. my question is straight forward
thx in advance..
Why do you want to do that?
You can prevent them from leaving the page by using Javascript, but if you can't use that, it's not possible to do anything about it.
Generally you should use the unload event in the body (in jQuery for instance, just add
jQuery(window).unload(function(evt){
if(!confirm('Do you really want to leave')){
evt.preventDefault();
}});
Prototype have something similar, and for pure Javascript, I guess that it still depends on the browser you're using, but window.unload = function(evt){return false;} might work.
Don't remember the correct syntax for it though.
but I do not know if you can limit that for only the back or if it will trigger for all the unloads (like clicking on a link, closing the browser etc.)
If you want to stop them because they might have unsaved data in a form, then that is ok. If you want to stop them from going back for another reason than that, I think you should rethink why.
Generally if using the back button can cause issues you already have bigger problems.
What you probably want to do is check that you do things like this:
Use POST for all requests that alter data
Use nonce's (unique ID's) to enure forms don't get submitted twice
I use noscript for this very reason. I insist on having control of my browser not the site that I am visiting. I only allow scripts for certain sites. For any site that disables my back button,I don't allow it to run scripts.

Resources