Steven S
Steven S

Reputation: 33

Does selenium IDE have a way to handle dynamic elements?

I was using selenium IDE to automate testing on a web page that has dynamic xpath in it. I noticed selenium IDE was capturing the xpath fine the first time playing it. Then after closing the browser and opening, of course the xpath has changed, but the target saved was the old xpath.

Is there a way to handle this in selenium?

I know I can use the .contains method but can i apply that to the target? Picture of selenium IDE firefox extension

Upvotes: 3

Views: 1051

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193068

To identify the dynamic elements you can construct dynamic locators. As couple of examples:

  • Using a css for a <span> tag with id attribute starting with abc:

    span[id^='abc']
    
  • Using a css for a <span> tag with class attribute containing pqr:

    span[class*='pqr']
    
  • Using a xpath for a <span> tag with value attribute ending with xyz:

    span[value$='xyz']
    
  • Using a xpath for a <span> tag with id attribute starting with abc:

    //span[starts-with(@id, 'abc')]
    
  • Using a xpath for a <span> tag with class attribute containing pqr:

    //span[contains(@class, 'pqr')]
    

Explanation of the dynamic CSS_SELECTOR

The wildcards are defined as follows:

  • ^ : To indicate an attribute value starts with
  • * : To indicate an attribute value contains
  • $ : To indicate an attribute value ends with

References

You can find a couple of relevant detailed discussions in:

Upvotes: 2

Related Questions