In Selenium IDE, can Locator use XPath and storedVars -
i have xpath select specific radio button item of html. enhance locator more dynamic using stored variable represent text xpath using lock on.
this current setup
command: click
target:
//*[contains(@for,'page149.question48.typechoiceoneanswerradiobutton.holder_ctl02') , text()="below 70 – may low"]
i replace literal text "below 70 – may low" variable. proposed target failing evaluate. hope have syntax incorrect.
can this? can use stored variables xpath locators?
proposed target:
//*[contains(@for,'page149.question48.typechoiceoneanswerradiobutton.holder_ctl02') , text()=${radiotext}]
edit: adding code. made simple example of html radio button list , isolated selenium commands. using selenium ide in firefox. commands example has comments.
sample html
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>untitled page</title> </head> <body> <table border="0" class="srvy_radiobuttonlist" id="ctl00_cphsurveycontrols_surveycategorypage_page51.question5.typechoiceoneanswerradiobutton.holder_ctl02"> <tbody> <tr> <td> <input type="radio" checked="checked" value="page51.question5.answer580" name="ctl00$cphsurveycontrols$surveycategorypage$page51.question5.typechoiceoneanswerradiobutton.holder$ctl02" id="ctl00_cphsurveycontrols_surveycategorypage_page51.question5.typechoiceoneanswerradiobutton.holder_ctl02_0"><label for="ctl00_cphsurveycontrols_surveycategorypage_page51.question5.typechoiceoneanswerradiobutton.holder_ctl02_0">male</label> </td> <td> <input type="radio" value="page51.question5.answer581" name="ctl00$cphsurveycontrols$surveycategorypage$page51.question5.typechoiceoneanswerradiobutton.holder$ctl02" id="ctl00_cphsurveycontrols_surveycategorypage_page51.question5.typechoiceoneanswerradiobutton.holder_ctl02_1"><label for="ctl00_cphsurveycontrols_surveycategorypage_page51.question5.typechoiceoneanswerradiobutton.holder_ctl02_1">female</label> </td> </tr> </tbody> </table> </body> </html>
mocked selenium ide
<?xml version="1.0" encoding="utf-8"?> <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head profile="http://selenium-ide.openqa.org/profiles/test-case"> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="selenium.base" href="http://localhost" /> <title>locatortest</title> </head> <body> <table cellpadding="1" cellspacing="1" border="1"> <thead> <tr><td rowspan="1" colspan="3">locatortest</td></tr> </thead><tbody> <!--select male--> <tr> <td>click</td> <td>//*[contains(@id,'page51.question5.typechoiceoneanswerradiobutton.holder_ctl02_0')]</td> <td></td> </tr> <tr> <td>store</td> <td>female</td> <td>gender</td> </tr> <tr> <td>asserttextpresent</td> <td>${gender}</td> <td></td> </tr> <tr> <td>asserttextpresent</td> <td>javascript{ storedvars['gender']}</td> <td></td> </tr> <!--fyi, locates first item in radio collection--> <tr> <td>click</td> <td>//*[contains(@for,'page51.question5.typechoiceoneanswerradiobutton.holder_ctl02')]</td> <td></td> </tr> <!--works select female--> <tr> <td>click</td> <td>//*[contains(@for,'page51.question5.typechoiceoneanswerradiobutton.holder_ctl02') , text()='female']</td> <td></td> </tr> <tr> <td>click</td> <td>//*[contains(@for,'page51.question5.typechoiceoneanswerradiobutton.holder_ctl02') , contains(text(),'female')]</td> <td></td> </tr> <!---- not found --> <tr> <td>click</td> <td>//*[contains(@for,'page51.question5.typechoiceoneanswerradiobutton.holder_ctl02') , contains(text(),${gender})]</td> <td></td> </tr> <!--works select female--> <tr> <td>click</td> <td>//*[contains(text(),'female')]</td> <td></td> </tr> <!---- not found --> <tr> <td>click</td> <td>//*[contains(text(),${gender})]</td> <td></td> </tr> </tbody></table> </body> </html>
you need quotation marks around variable.
//*[contains(text(),'${gender}')]
and yes, have used xpath locator stored variables, though not 'click' 'waitforxpathcount'. @ first didn't work , had resort printf-debugging cause. reason didn't work irrelevant here(i didn't set target appropriately), think list of relevant files of interest having trouble selenium ide.
location of files on mac:
~/library/application support/firefox/profiles/[your profile]/extensions/{a6fd85ed-e919-4a43-a5af-8da18bda539f}/chrome/content/selenium-core/scripts/
important files:
- selenium-api.js
core command handlers. ex.selenium.prototype.doclick
- selenium-browserbot.js
responsible interfacing browser.doclick
handler above callsbrowserbot.prototype.findelement
, instance. - selenium-executionloop.js
calls command handlers. importantly in case, preprocesses locator stringselenium.preprocessparameter(command.target)
.selenium.preprocessparameter
can found inselenium-api.js
. - htmlutils.js
providesxpathevaluator
how print ide log:
log.error("useful debugging information");
you need restart firefox each time make change selenium ide's internals (i couldn't find way reload on fly).
additionally, can test xpath expression $x("xpath/expr/with/stored/variables/replaced/accordingly")
on normal firefox js console.
Comments
Post a Comment