Friday, November 12, 2010

How to automatically click ok on "Authentication Required" popup

Lately, I've been doing some web scraping automation. For the most part, I'm using Selenium, but Selenium doesn't seem to be able to automatically click "OK" when an authentication window pops up.

This python code, works with Redhat's Dogtail to auto-magically click "OK" button on an "Authentication Required" popup:

from dogtail import tree
from dogtail.utils import run
from time import sleep
from os import environ, path, remove
import sys

#print tree.root.dump()
firefox = tree.root.application('Firefox')

#print firefox.dump()
#print dir(firefox)
#print firefox.findChildren()
auth_required = firefox.childNamed("Authentication Required")
#auth_required = firefox.child(name="Authentication Required")
ok_button = auth_required.childNamed("OK")
print 'ok button clicked now'
#print dir(ok_button)


Doing gui-automation this way may be a "bad idea", but I'm only doing this automation to scrape an internal webpage, and it only has to work on a very specific configuration -- Ubuntu 10.04 with Firefox.

Tuesday, November 2, 2010

Script to nuke specific onclick() behavior in Rally tool.

When you're editing your user stories in Rally the most irritating part is that you can't open all your stories in new tabs by holding down the ctrl key and clicking all the story links. The following greasemonkey script enables you to do that:

// Makes Rally tool do what it is supposed to.
// 2009.03.17, Ross Rogers
// Copyright (c) 2005, Mark Pilgrmim
// Released under the GPL license
// --------------------------------------------------------------------
// This is a Greasemonkey user script.
// To install, you need google's Chrome or
// Greasemonkey:
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
// To uninstall, go to Tools/Manage User Scripts,
// select "Hello World", and click Uninstall.
// --------------------------------------------------------------------
// ==UserScript==
// @name Rally Onclick Nuke
// @namespace
// @description Nukes the "onclick" attribute from user story links so you can
// CTRL click a link and have it open in a new tab. Also creates
// "accesskey" shortcuts for Save (alt+a), "edit_tags" (alt+t),
// and "apply" button (alt+a)
// @include https://*rally.sp*
// @include https://*slm/ar/edit.sp*
// ==/UserScript==

function remove_story_onclicks() {

console.log("running remove_story_onclicks\n");
var links = document.getElementsByTagName("a");
for (i = 0; i < links.length; i++) {
var node = links[i];
var link = node.getAttribute("href");
var className = node.getAttribute("class");
var is_edit_button = (className && className.indexOf("sprite-edit") > -1);
if (is_edit_button) {
var newHref = node.getAttribute("onclick").replace(/.*popup\('([^']*?)'.*/, "$1");
if (link && link.indexOf("slm/detail/ar/") > -1 ||
is_edit_button ) {
if (node.getAttribute("onclick")) {
console.log("removed attribute onclick\n");
var buttons = document.getElementsByTagName("button");
for (i = 0; i < buttons.length; i++) {
var button = buttons[i];
console.log("Iterating through buttons\n");
if (button.innerHTML.match(/^Save$/) ) {
console.log("setting Save button's accesskey to 's'\n");
if (button.innerHTML.match(/^Apply$/) ) {
console.log("setting Apply button's accesskey to 'a'\n");

var edit_tags_link = document.getElementById("edit_tags");
if (edit_tags_link) {
console.log("setting edit_tags-link's accesskey to 't'\n");


// override onclicks everywhere
var links = document.links;
for (i = 0; i < links.length; i++) {
var node = links[i];
if (node.getAttribute("onclick")) {
console.log("wrappering onclick\n");
var original_onclick = node.onclick;
function wrapper_onclick(e ) {
var ret = original_onclick(e);
return ret;
node.onclick = wrapper_onclick;

function document_onclick() {
console.log("document_onclick() called\n");

To install this, put it in a file named rally_onclick_nuke.user.js, then load it in chrome by dragging the file onto the browser. It should ask you at the bottom of the page if you want to install the extension, and you press yes.