Watir and javascript pop-up window - watir

I have just started to learn Watir... I'm stuck with this:
I try to make Watir click (and read the content) of this javascript popup window:
http://www.w3schools.com/js/tryit.asp?filename=tryjs_alert
My Watir code looks like this:
require 'watir'
b = Watir::Browser.start "www.w3schools.com/js/tryit.asp?filename=tryjs_alert"
b.maximize
b.frame(:name, "view").button(:text, "Show alert box").click
b.javascript_dialog.button('OK').click
..But it's not working, Watir is not clicking "OK" button on the popup Window.
I know that Watir-Webdriver can handle popup windows ("browser.alert.ok"), but can "classic" IE-only Watir do this (without any complicated hacks, using AutoIt / Sikuli etc)?
EDIT: I was able to remove popup window completely with this line:
b.frame(:name, "view").execute_script("window.alert = function() {}")
Better than nothing, now tests will not hang to popup windows, but I still can't confirm / read popup windows...

It looks like after Watir clicks the button to open the javascript dialog, it is waiting for something that it never gets.
The solution is to click the button with a click_no_wait. Try this instead:
require 'watir'
b = Watir::Browser.start "www.w3schools.com/js/tryit.asp?filename=tryjs_alert"
b.maximize
b.frame(:name, "view").button(:text, "Show alert box").click_no_wait
b.javascript_dialog.button('OK').click
Update: Just noticed that this documented on the Watir wiki - http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups (see first example).

Related

How do you click a button in a browser popup window

I'm new to using Watir and have a problem. Within my browser page there is an option to add a note. This brings up a window within the browser which has the following id:
span id="ui-id-2" class="ui-dialog-title">Add Note</span
I can't work out how to use the controls within this window such as the 'Save' button as Watir doesn't seem to recognise either the window or the controls
So if I wanted to use same type of Save button within the main browser it would be fine; I'd just use browser.button(:id=> "Save").click.
Trying to use it within the popup though won't work as Watir can't recognise it within the popup. Any ideas appreciated!

Handling Modal Dialog box from webpage in watir

So I'm writing a watir-webdriver test script, and my webpage is using javascript:window.print to present a modal window that I want to interact with. When I click the link that presents the modal window, watir-webdriver just sits there until eventually it times out and i see a Timeout::Error on the console window. This is before attempting to interact with the new window at all. how do I tell it to move on without waiting?
After that whole execution is not responsive. Its not proceeding with next execution it gets struck there. tried the below solution too
element.focus element.send_keys :return
but no luck, Could anyone know how to resolve this modal dialogbox from webpage.
Thanks
get
I am using Firefox with Watir-webdriver.
browser.a:(:href => 'javascript:window.print()').click
this opens the Print dialog box. Which is the normal print dialog box from teh Firefox browser.
It just waits here and doesn't execute anything after that till i click manually or it timesout.

How to open the default popup from context menu in a chrome extension

I have developed a chrome extension that opens a popup when I click on the icon near the address bar. Everything works fine, however I want to add some functionality to it. So I thought I'd also add a context menu item so that the user can simply search for the highlighted word. I want the popup to showup when the user clicks on the item in the context menu(the default popup in the top right corner and not a new popup window or a new tab).
Can I have this functionality? If yes, how do I implement it?
You can't make the popup page show programmatically as if the user clicked it.
However, you can still have something display based on the background script / content menu click. There are 4 main options for your background script:
Open a new tab to the popup.html page
Programmatic injection of javascript to construct a popup-like dialog on the page
Content script message passing to do the same as above, using a running content-script.
Use the notifications API for a simple minimally stylized message to the user.
Options 2, 3, 4 will allow the user to stay on their tab without any navigation. The notifications API route is the simplest to use if you just want some quick notification to the user, and there are fewer security snags. 2 and 3 require more book-keeping, but you can make the dialog look like your popup.
There should be an API for it now (as in 2023)
https://developer.chrome.com/docs/extensions/reference/action/#method-openPopup
update: tried, but failed, there was a bug.
https://github.com/GoogleChrome/developer.chrome.com/issues/2602
hope they fix it soon.
I was looking for extensions that I have already been used, but forget its name. This extension opened up the result into Context Menu, without open new TAB or popup.
may be useful
https://developer.chrome.com/extensions/contextMenus

Chrome: How to close tab from within a page?

Is there a way to close Chrome Tab from within a html page?
What i search for is some javascript that will will say: Click here to close tab!
I think you can just use the window.close() function, just like you would when closing a popup window or a regular window:
http://www.javascript-coder.com/window-popup/javascript-window-close.phtml
Update: This no longer seems to work on newer versions of Chrome. However, opening a new window with:
Open window
and using
Close window
in foo.html works for me in Chrome 17. See also http://www.google.com/support/forum/p/Chrome/thread?tid=23c03746e3aa03f9&hl=en.

Yahoo UI the popup implementation with YAHOO.widget.Dialog

I used the Yahoo.widget.dialog to implement a popup window. Currently, it popups only on the page which is belongs. If I am working on the other (tab browser) pages. The popup window will be not seen.Could somebody supply some help for this ?Thanks
You could either switch to window.alert() or use window.open() to open a new pop-up window containing your content.
Neither one is something I'd personally want to experience, but those are your two options for opening a pop-up outside the page. Window.open will get caught by many pop-up blockers so you'll need to watch for that.

Resources