Archive for March, 2011

IE Automation Using Powershell

I’m trying to write some cheesy tests for a complicated page I want to rewrite in powershell using the IE com application. Here’s some code, slightly anonymized

$url = "http://localhost:123123/SomePage.aspx"

function waitforpageload {
    while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 1000; } 
# cheesy way to find dom elements whose ID or name end with the short control name
# (I'm too lazy to depend on the full ID, or turn off the name mangling does)
function findInput {param ($name)
    $ie.Document.getElementsByTagName("input") | where-object {$ -and $$name)}
function findDiv {param ($name)
    $ie.Document.getElementsByTagName("div") | where-object {$ -and $$name)}

$ie = New-Object -com internetexplorer.application
$ie.visible = $true

# first step of this page:
$chk = findInput("chkAgree")
$btn = findInput("btnContinue")

# second step of this page
$txt = findInput("txtFirstName")
$txt.value = "First"
$txt = findInput("txtLastName");
$txt.value = "Last"

# example of setting a value in a telerik combo by executing javascript
$cbo = findDiv("cboNamePrefix") # Find the dom element for the id...

That’s all for now. I’m sure you can extend this to your needs.

Leave a comment

Moving GFWL/Dirt2 savegames to new computer

Copy GFWL profile from
C:\Users\Nick Winters\AppData\Local\Microsoft\XLive
to new computer

also copy savegames from:
C:\Users\Nick Winters\Documents\My Games\DiRT2

Then start the game and it should work…

I then hit Home after signing in, clicked on the leftmost button of the GFWL tabs and “Enable Auto Sign in” so I don’t have to be annoyed by GFWL much again.

On my XP Machine the folders were:
C:\Documents and Settings\Nick Winters\Local Settings\Application Data\Microsoft\XLive
C:\Documents and Settings\Nick Winters\My Documents\My Games\DiRT2

Leave a comment

SQL Profiler for SQL Express

I learned of this tool from the talk by Hattan Shobokshi

Leave a comment

Named arguments in c# 4

A pet peeve of mine is boolean parameters to methods in c#. Here’s an example.

something.Frob(foo, true);

Yeah, so what’s that “true” mean?

I’ve seen some with a standard like this:

bool frobChildren = true;
something.Frob(foo, frobChildren);

That works. But in c# 4 you can also do this:

something.Frob(foo, frobChildren: true);

or an in-context example:

return string.Compare(string1, string2, ignoreCase: true);

Leave a comment