Search code examples
xpathwebdrivercodeceptiondynamicform

Test Codeception/webdriver And Dynamic Form ID


Just a question, i try to perform acceptance test (fill a field) on form with an ID generated dynamically on every refresh. I am looking for a method to grab the form id, or to use partial xpath, i didnt find it.

<input type="text"     name="searchform_fb1831c63342af1bc6b8744181e2cc5b[simpleCriteria][NAME]"     id="searchform_fb1831c63342af1bc6b8744181e2cc5b-simpleCriteria-NAME" value=""     size="40" class="manage_ul_error text-input">

Any suggestion will be welcome thank you.


Solution

  • One option is to check id attribute for containing searchform_:

    //input[@type='text' and contains(@id, 'searchform_')]
    

    or, for starting with:

    //input[@type='text' and starts-with(@id, 'searchform_')]
    

    You may also check for class additionally:

    //input[@type='text' and @class='manage_ul_error text-input' and starts-with(@id, 'searchform_')]