Webdriver cheat sheet

▪ Core Classes
WebDriver
WebElement
By

▪ Visit page
webdriver.get(”url”)

▪ get page title, page source string
webdriver.getTitle(), getPageSource()

▪ Find Element(s)
WebElement elm = webdriver.findElement(s)(By byclause)

▪ By selector where selector in { name, id, tagname, name, xpath, cssName, cssSelector }
webdriver.findElement(By.<selector>(”selectorString”))

▪ Get text from a node
webElement.getText()

▪ Fill in input boxes
webElement.sendKeys(”value”)

▪ Click input buttons (radio, checkbox, submit, image)
webElement.click()

▪ Select option
webElement.setSelected()

▪ Submit form
webElement.submit()

▪ Waiting for a condition (ajax + dhtml)

ExpectedCondition<Boolean> cond = new ExpectedCondition<Boolean>() {
    @Override
    public Boolean apply(WebDriver arg0) { }
};
WebDriverWait wait = new WebDriverWait(driver, waitTime);
wait.until(cond);

▪ Configure implicit wait timeouts

driver.manage().timeouts().implicitlyWait(waitTime, TimeUnit.SECONDS);

Leave a Comment

Running MSI installer as an admin user on XP

I was a little perplexed when I tried to run a windows installer (.msi) as an admin user on my windows XP laptop. On a right click, I could not find ‘run as’ option. Weird, I thought.
Here is the workaround I used.
1. Right click on Console2 application (I use that one instead of the default windows console)
2. select run as admin, entered my admin user and password.
3. now on command line, i gave msiexec /i [Path to .msi file]

That’s it. I am installing msi programs as an admin user.

Comments off

eclipse plug-in cache

While working on an eclipse plug-in , I realized that eclipse maintains a cached copy of all the plug-in metadata. It can get into a weird state when you are trying to test your deployment into a local copy of eclipse. I got into a state where my installed plug-in was not getting activated. I had to find a hard way, that you can start eclipse with a command line option “-clean” that refreshes the plug-in metadata cache and loads any new installed plug-ins. I do not obviously think that you would need to do that every time you install a new plug-in, but if you get into a state that’s exhibiting this behavior, remember the -clean option.

Comments off

Sign your jar with your own certificate

Signing jar files has been an essential part of publishing your java programs on web. You have to use java web start based JNLP protocol to launch your java app from the browser. Much like the active-x plug-ins and applets, the java apps that you download via JNLP are also bound by strict security regulations. In my limited experience in publishing my own version of sudoku, I had to get the runnable jar signed with some certificate. I tried using free certificate authority like cacert, but what I have found to be the most convenient is just create self-signed certificates for testing your own published work. It gives you ability to test the entire work flow of publishing the jar and its corresponding jnlp, and downloading it from the browser.
Here are the two simple commands that lets you create a self-signed certificate and sign a jar with it.

keytool -genkey -alias my_home -keystore amit.jks
jarsigner -keystore ~/amit.jks -signedjar sudoku.signed.jar sudoku.jar my_home

Thant is all there is. But it took me about half a day to figure this thing out, so I thought I should share it with everyone.
You can download my sudoku puzzle, implemented using SWT for its GUI. It should give you a native look at feel for your platform.
The source code for the app can be downloaded from google code repository

Comments off

Why does not os.system(”cd ..”) work in python ?

I dont understand this. In python, os.system function works perfectly for almost all the commands that interact with your shell ( bash, zsh or even windows shell WSH ), but when it comes to changing directories, one has to use os.chdir() function as os.system(”cd myfolder”) does not work. It does not throw any exception, but the command just does not do anything. Is that a bug ?

Comments off