Selenium RC: Xpath of the link is changed when I refresh the page



  • Selenium RC: Xpath of the link is changed when I refresh the page, and when I run the code it shows "Exception in thread "main" com.thoughtworks.selenium.SeleniumException: ERROR: Element //*[@id='yui-gen79'] not found".

    How do I handle this error?

    First:

    //*[@id='yui-gen79']
    

    After

    //*[@id='yui-gen98']
    


  • With dynamically generated element ids, sometimes I find that you can use contains along with a longer xpath locator to match the element. In the sample code provided it looks like only a single anchor element has an id attribute that contains the text "yui-gen" so I would suggest trying

    //a[contains(@id, 'yui-gen')] 
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2