Sometimes you want to dynamically change the XPATH or CSS used in a specific object from within the test script itself. This article explains the process for doing this.
The solution is to
override the built-in HTML locator functionality (used when
testing Web applications) and modify the XPATH / CSS locator on the fly.
The following simple example will show you how to adjust the XPATH or CSS of a specific object:
Normally you'd use a learned object such as:
SeS('Log_In').DoClick(0,0,true);
to override the XPATH locator, we just pass it through as an extra JavaScript object parameter:
SeS('Log_In', { xpath: '/html/body//a[@id=\'HeadLoginView_HeadLoginStatus2\']' } ).DoClick();
Or to use CSS we'd simply use:
SeS('Log_In', { xpath: 'css=html > body > form#ctl01 > div:nth-of-type(3) > div:first-of-type > div:nth-of-type(2) > a#HeadLoginView_HeadLoginStatus' } ).DoClick();
Spira Helps You Deliver Quality Software, Faster and With Lower Risk

And if you have any questions, please email or call us at +1 (202) 558-6885