Monday, August 24, 2009

Selenium troubleshooting

Problem 1: Something on the page isn't found because it isn't ready yet
Solution: Use clickAndWait

Problem 2: It won't record my password or another text field
Solution: Click off the text field (in other words, click elsewhere) after you type it. Usually Selenium will successfully record at that point. If you are still having trouble, try entering the command yourself directly into the Selenium script.

Problem 3: I can't get a dropdown menu to appear for a type-ahead field, perhaps because it's JavaScript
Solution: Use the "fireEvent" command on the HTML field. The value "focus" will cause, for example, the JavaScript focus event to be triggered. If the dropdown menu looks for that event, then firing it will cause the dropdown to appear. Also, use the "typeKeys" command to enter the text in the type-ahead field that informs the dropdown.

Problem 4: I can't figure out how to identify an element (link, button, table cell...) reliably
Solution: Ask a developer if there is a way to include an id or name for the element that can be uniquely identified (i.e. this is a "testability" issue). Failing that, use XPath targets. For example, use clickAndWait with a target that looks like //a[@href='myurl'] (that is an XPath query). You can even use Firebug to locate XPath for a given element. With Firebug installed and enabled (on Windows press F12 to enable), click Inspect, highlight the HTML element on the page, click it to select it, right-click its representation in the script windows in the debugger, and click Copy XPath. You may need to edit the XPath before entering it into the Selenium target. Selenium always requires an extra / (frontslash) at the beginning of XPath targets.

Problem 5: Running Java Selenium tests via Selenium RC, clicking my link doesn't work in IE (or vice versa, in Firefox)
Solution: Firefox and IE handle ampersands (&) differently, among other things. Don't use the "click" command on links that contain ampersands.

No comments:

Copyright 2011 by William Cain