Watir-Webdriver: closing popups with no window name

After some time googling for a simple way to interact with annoying popups. I found a few but couldn’t really solve what I wanted to do. Most articles showed a way to switch to the popup window by using the window name. In my case, the window I was trying to work with didn’t have a name. So I did what was best, dive into the watir-webdriver gem and found a solution. Funny thing is that the code is probably better documented than anywhere else.

The watir-webdriver browser object has an alert method which switches the driver to that window and returns an instance of the Alert class. Nice, half the work is down with is method alone. You can take the return object and call:

Alert#text – returns the text on the alert box
Alert#ok – closes or accepts the prompt
Alert#close – closes or cancels the prompt

Parsing HTML with Nokogiri

Its insane what xpath can do for you. I don’t think there has been anything that Nokogiri haven’t done for me. For instance parsing this:

results = ‘<tbody>
<td><a class=”view” href=”?id=1&amp;o=r”>All Managed Clients</a></td>
<td><a class=”view” href=”?id=2&amp;o=r”>All Managed Servers</a></td>
<td><a class=”view” href=”?id=10&amp;o=r”>AutomationUIGroup</a></td>
<td><a class=”view” href=”?id=4&amp;o=r”>Test JAMF Eau Claire</a></td>

This snippet of HTML will change so you can’t depend on your value to be in the same place. One good way to find the numerical value associated with the textual value is to do this:

numerical_value = Nokogiri::HTML(results).xpath(“//tr[td/a = 'AutomationUIGroup']/td/text()”).to_s

Breaking it down…

- Pass the HTML to Nokogiri; it subsequently returns a Nokogiri document


- We call the document’s xpath


- We pass in the path that we want to find. We want to look at any <tr> element that has a nested <td> element and a <a> element. The text nested in the <a> element should equal ‘AutomationUIGroup’. If that is true, we want to get the next <td> element’s text value.

“//tr[td/a = 'AutomationUIGroup']/td/text()”

Changing password in SourceTree with Git-SVN

So I recently changed my AD password at work and using SourceTree for Git-SVN. It works well for me. I noticed that I could not push my commits because of password failure. So I googled. Found out that Git-SVN uses your existing SVN setup. On a Mac, you can change your password if you had it stored in plain text: ~/.subversion/auth/svn.simple. There should be a few files there. You can simply use a commandline text editor to change your password. If you didn’t store you password in plain text, open up Keychain. Select the “login” keychain and “password” under category. Find your password and double click it, check the “Show password” checkbox, authenticate and change it! Done.

Helpful Mac Terminal Keyboard Commands

Wish I would have found this earlier:
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + L Clears the Screen, similar to the clear command
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H Same as backspace
Ctrl + R Let’s you search through previously used commands
Ctrl + C Kill whatever you are running
Ctrl + D Exit the current shell
Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W Delete the word before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + T Swap the last two characters before the cursor
Esc + T Swap the last two words before the cursor

From: http://osxdaily.com/2006/12/19/command-line-keyboard-shortcuts-for-mac-os-x/