1

I am new to Selenium IDE.

In my Web application, while playing back the recorded events, some internal id in XPath expression gets changed dynamically.

E.g.: (//*[@id='edit_1_undefined']) in this script, id 1 changes to 2 and so on. So playback failed. I need to update Id in Xpath manually.

Is there any solution to this problem?

3 Answers 3

3

This is the problem with Selenium IDE or any other recorder for that matter. It doesn't deal with dynamic data very well. If you really want to solve this problem without switching tools, you can try to use an xpath with an static anchor that's higher up in the DOM.

For instance, you just start at //*[@id='edit_1_undefined'] and lets assume this element is an input field. Now lets just suppose that this is under a div with a static id of editList. You could do something like this;

//*[@id='editList']/input

That's of course making a few assumptions about your layout, but hopefully that can help.

However, if you wanted to move to a related framework that gives you much more power, the underlying engine for selenium has an open API that many languages implement (Called webdriver). For example, there is watir-webdriver which is a ruby gem that lets you use the selenium engine (Check out http://watirwebdriver.com/). I believe Selenium IDE even lets you 'record' into ruby code directly, though I'm not sure how reliable it is.

2

You've discovered one of the many flaws in automation, especially record n play automation.

Either it make sure the app you are testing never changes its identifiers or you don't use record and replay and use code that can be more 'intelligent'

2

Does the code under test have unique semantic CSS classes you can rely on instead of an ID?

For example, this page has the following HTML for showing an answer <div id="answer-5968" class="answer" data-answerid="5968" >. Instead of searching for this element by its ID, you can rely on class="answer" in your markup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.