XPATH

From iMacros
Jump to: navigation, search

XPATH test macro: TO BE CONFIRMED

TAB T=1     
TAB CLOSEALLOTHERS  
URL GOTO=http://demo.imacros.net/Automate/TestForm1
TAG XPATH="id('demo')/div/center/table/tbody/tr[1]/td[3]/small/input[1]" CONTENT="Tom Tester"
TAG XPATH="id('demo')/div/center/table/tbody/tr[2]/td[3]/select" CONTENT=$Pizza
TAG XPATH="id('demo')/div/center/table/tbody/tr[3]/td[3]/select" CONTENT=$Water
TAG XPATH="id('demo')/div/center/table/tbody/tr[3]/td[3]/input[1]" CONTENT=YES 
TAG XPATH="id('demo')/div/center/table/tbody/tr[4]/td[3]/select" CONTENT=$Apple<SP>Pie:$Fruits 
TAG XPATH="id('demo')/div/center/table/tbody/tr[5]/td[3]/input[1]" CONTENT=Yes 
SET !ENCRYPTION NO
TAG XPATH="id('demo')/div/center/table/tbody/tr[5]/td[3]/input[2]" CONTENT=demo123 
TAG XPATH="id('demo')/div/center/table/tbody/tr[6]/td[3]/textarea" CONTENT="Hi!\n\niMacros fills  forms;-)\n\nTom"
TAG XPATH="id('demo')/div/center/table/tbody/tr[8]/td[3]/input" 
WAIT SECONDS=5
URL GOTO=http://demo.imacros.net/Automate/OK

You can use XPath checker to get the element's XPath.

XPath support is available from iMacros v7 onwards and also in the free Firefox and Chrome add-ons.Due to the different underlying browser engines, not all XPATH commands behave exactly the same on every browser. One case is the id() function as it is used in the example above, which is not supported in iMacros 7. One can get the same result by using instead:

VERSION BUILD=10.4.28.1074
TAB T=1
TAB CLOSEALLOTHERS
URL GOTO=http://demo.imacros.net/Automate/TestForm1
TAG XPATH="//form[@id='demo']/fieldset[1]/ol/li[1]/input[1]" CONTENT="Tom Tester"
TAG XPATH="//form[@id='demo']/fieldset[1]/ol/li[2]/select" CONTENT=%Pizza
TAG XPATH="//form[@id='demo']/fieldset[1]/ol/li[3]/select" CONTENT=%Coke
TAG XPATH="//form[@id='demo']/fieldset[1]/ol/li[4]/input[2]" CONTENT=YES
TAG XPATH="//form[@id='demo']/fieldset[1]/ol/li[5]/select" CONTENT=$Apple<SP>Pie:$Fruits
TAG XPATH="//form[@id='demo']/fieldset[1]/ol/li[6]/input[1]" CONTENT=YES
SET !ENCRYPTION NO
TAG XPATH="//form[@id='demo']/fieldset[1]/ol/li[6]/input[2]" CONTENT=tester
TAG XPATH="//form[@id='demo']/fieldset[1]/ol/li[7]/textarea" CONTENT="Hi!\n\n \t iMacros can fill  forms;-)\n\nTom"


TAG XPATH="//form[@id='demo']/fieldset[2]/button"
WAIT SECONDS=5
URL GOTO=http://demo.imacros.net/Automate/OK

The macro above also works in the Firefox and Chrome addons.

Please report to us any issues that you encounter. We can verify if that is a bug in our implementation or a restriction of the web browser itself.


Related forum posts: