Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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'

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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