您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

reference.rst 31KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. Reference
  2. ======================
  3. Use this section to look up information on steps, helper functions and run options you can use. You can explore using the navigation headers.
  4. .. _step-reference:
  5. Steps
  6. ------------------
  7. The steps you can use in TagUI are listed here.
  8. Mouse and keyboard
  9. ********************
  10. .. _click:
  11. click
  12. ##################
  13. | Left clicks on the identifier.
  14. | Can use :ref:`DOM <dom>`, :ref:`XPath <xpath>`, :ref:`Point <point>`, :ref:`Image <image>` identifiers.
  15. .. code-block:: none
  16. click [DOM/XPath/Point/Image]
  17. *Examples*
  18. .. code-block:: none
  19. click Main concepts
  20. click //nav/div/div[2]/ul/li[4]/ul/li[1]/a
  21. click (500,200)
  22. click button.png
  23. rclick
  24. ##################
  25. | Right clicks on the identifier.
  26. | Can use :ref:`DOM <dom>`, :ref:`XPath <xpath>`, :ref:`Point <point>`, :ref:`Image <image>` identifiers.
  27. .. code-block:: none
  28. rclick [DOM/XPath/Point/Image]
  29. See :ref:`click <click>` for examples.
  30. dclick
  31. ##################
  32. | Double left clicks on the identifier.
  33. | Can use :ref:`DOM <dom>`, :ref:`XPath <xpath>`, :ref:`Point <point>`, :ref:`Image <image>` identifiers.
  34. .. code-block:: none
  35. dclick [DOM/XPath/Point/Image]
  36. See :ref:`click <click>` for examples.
  37. hover
  38. ##################
  39. | Moves mouse cursor to the identifier.
  40. | Can use :ref:`DOM <dom>`, :ref:`XPath <xpath>`, :ref:`Point <point>`, :ref:`Image <image>` identifiers.
  41. .. code-block:: none
  42. hover [DOM/XPath/Point/Image]
  43. See :ref:`click <click>` for examples.
  44. type
  45. ##################
  46. | Types into a web input. You can use [clear] to clear the field and [enter] to hit the Enter key.
  47. | Can use :ref:`DOM <dom>`, :ref:`XPath <xpath>`, :ref:`Point <point>`, :ref:`Image <image>` identifiers.
  48. .. code-block:: none
  49. type [DOM/XPath/Point/Image] as [text to type]
  50. *Examples*
  51. .. code-block:: none
  52. type search-term as John Wick
  53. type //input[@name="search"] as John Wick
  54. type (500,200) as John Wick
  55. type input_field.png as John Wick
  56. type search-term as [clear]John Wick[enter]
  57. type //input[@name="search"] as [clear]John Wick[enter]
  58. type (500,200) as [clear]John Wick[enter]
  59. type input_field.png as [clear]John Wick[enter]
  60. keyboard
  61. ##################
  62. Enters keystrokes directly.
  63. .. code-block:: none
  64. keyboard [keys]
  65. You can use the following special keys:
  66. - [shift] [ctrl] [alt] [win] [cmd] [enter]
  67. - [space] [tab] [esc] [backspace] [delete] [clear]
  68. - [up] [down] [left] [right] [pageup] [pagedown]
  69. - [home] [end] [insert] [f1] .. [f15]
  70. - [printscreen] [scrolllock] [pause] [capslock] [numlock]
  71. *Examples*
  72. .. code-block:: none
  73. keyboard [win]run[enter]
  74. keyboard [printscreen]
  75. keyboard [ctrl]c
  76. keyboard [tab][tab][tab][enter]
  77. keyboard [cmd][space]
  78. keyboard safari[enter]
  79. keyboard [cmd]c
  80. mouse
  81. ####################
  82. | Explicitly sends a mouse event at the current mouse position.
  83. | In most cases, you want you use :ref:`click <click>` instead.
  84. .. code-block:: none
  85. mouse down
  86. mouse up
  87. Web
  88. *******************
  89. visit
  90. #####################
  91. Visits the provided URL.
  92. .. code-block:: none
  93. [URL]
  94. *Examples*
  95. .. code-block:: none
  96. https://google.com
  97. select
  98. #####################
  99. | Selects a dropdown option in a web input.
  100. | Can use :ref:`DOM <dom>`, :ref:`XPath <xpath>` identifiers.
  101. .. code-block:: none
  102. select [DOM/XPath of select input element] as [option value or text]
  103. *Examples*
  104. .. code-block:: none
  105. select variant as blue
  106. table
  107. #####################
  108. Saves table data to a csv file, base on the table number on webpage or its :ref:`XPath <xpath>` identifier.
  109. .. code-block:: none
  110. table [table number] to [filename.csv]
  111. table [XPath] to [filename.csv]
  112. *Examples*
  113. .. code-block:: none
  114. table 1 to regional_exchange_rates.csv
  115. table (//table)[2] to global_exchange_rates.csv
  116. table //table[@name='report'] to report.csv
  117. popup
  118. #####################
  119. Modifies the next steps to be run in a new tab.
  120. .. code-block:: none
  121. popup [unique part of new tab's URL]
  122. [steps]
  123. *Examples*
  124. .. code-block:: none
  125. popup confirm
  126. click Confirm
  127. frame
  128. #####################
  129. Modifies the next steps to use the DOM or XPath in a frame or subframe.
  130. .. code-block:: none
  131. frame [frame name]
  132. [steps]
  133. frame [frame name] | [subframe name]
  134. [steps]
  135. *Examples*
  136. .. code-block:: none
  137. frame navigation
  138. click Products
  139. frame main | register
  140. click Register
  141. download to
  142. #####################
  143. | Specifies a location to store file downloads. The default location is the folder of the TagUI flow.
  144. .. code-block:: none
  145. download to [folder location]
  146. upload
  147. #####################
  148. | Uploads file to a website.
  149. | Only :ref:`DOM <dom>` identifier can be used.
  150. .. code-block:: none
  151. upload [DOM of upload element] as [filename]
  152. *Examples*
  153. .. code-block:: none
  154. upload #element_id as report.csv
  155. api
  156. #####################
  157. Call a web API and save the raw response to the variable ``api_result``.
  158. If the response is in JSON, ``api_json`` will automatically be created.
  159. .. code-block:: none
  160. api https://some-api-url
  161. *Examples*
  162. .. code-block:: none
  163. api https://api.github.com/repos/kelaberetiv/TagUI/releases
  164. echo `api_result`
  165. author = api_json[0].author.login
  166. For an advanced example of using api step, setting POST/GET method, header and body, `see this example from aito.ai <https://aito.document360.io/docs/tagui>`_ - a web-based machine learning solution for no-coders and RPA developers. In the example, ``api`` step is used to make a machine-learning inference to generate the account code of an invoice item, based on its description and price. aito.ai's free tier comes with 2000 API calls/month and it works perfectly with TagUI.
  167. Excel
  168. ********************
  169. Perform read, write, copy, delete actions on Excel files using standard Excel formula like this one ``[workbook]sheet!range``. This feature works with both Windows and Mac Excel apps. `See this link <https://github.com/kelaberetiv/TagUI/issues/1081#issuecomment-902058917>`_ for notes of passed test cases and known limitations for this feature. To access a password-protected Excel file, use ``excel_password = 'password'``.
  170. variables
  171. ###################
  172. You can use variables in your Excel formula, for eg ``range`` or ``sheet``. Various Excel file formats are supported, be sure to put the file's .extension as part of the formula so that TagUI can recognise that the instruction is an Excel step instead of some JavaScript code.
  173. .. code-block:: none
  174. [`workbook`.xlsx]`sheet`!`range` = 123
  175. data = [`workbook`.xlsx]`sheet`!`range`
  176. visibility
  177. ###################
  178. By default, the Excel app will be opened and run in the background. If you want the automated actions on Excel to be in focus in foreground, you can set it with ``excel_focus = true`` in your workflow. Use ``excel_focus = false`` to set it off again in your workflow.
  179. For some usage scenarios, you might not even want the Excel app to be visible in the background. In that case, you can set ``excel_visible = false`` in your workflow to run Excel invisibly. Use ``excel_visible = true`` to make Excel visible again in your RPA workflow.
  180. read
  181. ###################
  182. Read data from Excel files. Both relative and absolute file paths supported. Error will be shown if the specified file or sheet does not exist. In below line, range can be a cell or range in Excel.
  183. .. code-block:: none
  184. variable = [workbook]sheet!range
  185. Reading columns and rows can be done using standard Excel formula for range, for example A:A (column A), B:D (columns B to D), 2:2 (row 2), 3:5 (rows 3 to 5). There is no standard Excel formula for selecting the entire range of a sheet, so you will have to provide the actual range required.
  186. *Examples*
  187. .. code-block:: none
  188. top_profit = [Monthly Report.xlsx]August!E10
  189. top_salesman = [Monthly Report.xlsx]August!E11
  190. data_array = [Quarterly Metrics.xlsx]Main!B3:G100
  191. data_array = [C:\Reports\June.xls]Sheet1!A1:C2
  192. data_array = [C:\Reports\June.xls]Sheet1!A:A
  193. data_array = [C:\Reports\June.xls]Sheet1!B:D
  194. data_array = [C:\Reports\June.xls]Sheet1!2:2
  195. data_array = [C:\Reports\June.xls]Sheet1!3:5
  196. TagUI's backend language is JavaScript, thus data_array can be used just like a JavaScript array.
  197. .. code-block:: none
  198. // to work on data in data_array cell by cell
  199. for row from 0 to data_array.length-1
  200. for col from 0 to data_array[row].length-1
  201. echo `data_array[row][col]`
  202. Note - There was a limitation on reading multiple rows and columns, for eg B:D and 3:5 (data array returned will be a 1 x N array instead of the correct row x column array). This is now fixed in v6.87. Get your copy with ``tagui update`` command or from MS Word Plug-in ``Update TagUI`` button.
  203. write
  204. ###################
  205. Write data to Excel files. Both relative and absolute file paths supported. If the specified file does not exist, a new file will be created. If the sheet does not exist, a new sheet will be created. If the data is an array, the given cell will be used as the top-left cell to write the range of cells.
  206. .. code-block:: none
  207. [workbook]sheet!cell = variable
  208. *Examples*
  209. .. code-block:: none
  210. [Monthly Report.xlsx]August!E10 = 12345
  211. [Monthly Report.xlsx]August!E11 = "Alan"
  212. [Monthly Report.xlsx]August!E12 = variable
  213. [Quarterly Metrics.xlsx]Main!B3 = data_array
  214. TagUI's backend language is JavaScript, thus range data can be defined just like a JavaScript array.
  215. .. code-block:: none
  216. // to assign a set of range data with 2 rows of 3 columns
  217. [C:\Reports\June.xls]Sheet1!A1 = [[1, 2, 3], [4, 5, 6]]
  218. [C:\Reports\June.xls]Sheet1!A1 = [[variable_1, variable_2, variable_3], [4, 5, 6]]
  219. // example spreadsheet data with #, name and country
  220. [Participants.xlsx]Sheet1!A1 = [['1', 'John', 'USA'], [2, 'Jenny', 'Russia'], [3, 'Javier', 'Serbia']]
  221. // get the next row count for the example spreadsheet
  222. column_A = [Participants.xlsx]Sheet1!A:A
  223. next_row = column_A.length + 1
  224. // write a new row accordingly to example spreadsheet
  225. [Participants.xlsx]Sheet1!A`next_row` = [[next_row, 'Janice', 'Brazil']]
  226. copy
  227. ###################
  228. Copy data across Excel files. Both relative and absolute file paths supported. Error will be shown if the specified source file or sheet does not exist. If the specified destination file does not exist, a new file will be created. If the destination sheet does not exist, a new sheet will be created. If the data is an array, the given cell will be used as the top-left cell to write the range of cells.
  229. .. code-block:: none
  230. [workbook]sheet!cell = [workbook]sheet!range
  231. *Examples*
  232. .. code-block:: none
  233. [Monthly Report.xlsx]August!A1 = [Jennifer Report.xlsx]August!A1
  234. [Monthly Report.xlsx]August!A1 = [Jennifer Report.xlsx]August!A1:E200
  235. delete
  236. ###################
  237. Delete data in Excel files. Both relative and absolute file paths supported. Error will be shown if the specified file or sheet does not exist. Delete a range of cells by assigning an empty array to it.
  238. .. code-block:: none
  239. [workbook]sheet!cell = ""
  240. *Examples*
  241. .. code-block:: none
  242. [Monthly Report.xlsx]August!E10 = ""
  243. [Quarterly Metrics.xlsx]Main!A1 = [["", "", ""], ["", "", ""]]
  244. Word
  245. ********************
  246. You can read the text contents of a Microsoft Word document simply by assigning its filename to a variable as follows. TagUI will automate Microsoft Word to copy out the text contents and assign to the variable. Note that you need to have Microsoft Word installed on your computer. This feature works for both Windows and Mac.
  247. *Examples for Windows*
  248. .. code-block:: none
  249. word_text = [Research Report.docx]
  250. word_text = [C:\Users\Jennifer\Desktop\Report.docx]
  251. word_text = [FY2021 Reports\Research Report.docx]
  252. filename = 'C:\\Users\\Jennifer\\Desktop\\Report'
  253. word_text = [`filename`.docx]
  254. filename = 'Research Report'
  255. word_text = [`filename`.docx]
  256. *Examples for Mac*
  257. .. code-block:: none
  258. word_text = [Research Report.docx]
  259. word_text = [/Users/jennifer/Desktop/Report.docx]
  260. word_text = [FY2021 Reports/Research Report.docx]
  261. filename = '/Users/jennifer/Desktop/Report'
  262. word_text = [`filename`.docx]
  263. filename = 'Research Report'
  264. word_text = [`filename`.docx]
  265. After reading the text content into a variable, you can process it using TagUI's helper functions such as get_text() and del_chars() to retrieve specific information required for your RPA scenario. Standard JavaScript functions can also be used to do string processing, for more information google ``javascript how to xxxx``. After reading the text content from a Word document, TagUI will close Microsoft Word and continue with the rest of the automation steps.
  266. PDF
  267. ********************
  268. You can read the text contents of a PDF file simply by assigning its filename to a variable as follows. TagUI will automate the PDF viewer app to copy out the text contents and assign to the variable. On Windows, you will need the free `Adobe Acrobat Reader <https://get.adobe.com/reader/>`_ and set it as your default PDF viewer. On Mac, TagUI will use the default Preview app that can already view PDF files.
  269. *Examples for Windows*
  270. .. code-block:: none
  271. pdf_text = [Research Report.pdf]
  272. pdf_text = [C:\Users\Jennifer\Desktop\Report.pdf]
  273. pdf_text = [FY2021 Reports\Research Report.pdf]
  274. filename = 'C:\\Users\\Jennifer\\Desktop\\Report'
  275. pdf_text = [`filename`.pdf]
  276. filename = 'Research Report'
  277. pdf_text = [`filename`.pdf]
  278. *Examples for Mac*
  279. .. code-block:: none
  280. pdf_text = [Research Report.pdf]
  281. pdf_text = [/Users/jennifer/Desktop/Report.pdf]
  282. pdf_text = [FY2021 Reports/Research Report.pdf]
  283. filename = '/Users/jennifer/Desktop/Report'
  284. pdf_text = [`filename`.pdf]
  285. filename = 'Research Report'
  286. pdf_text = [`filename`.pdf]
  287. After reading the text content into a variable, you can process it using TagUI's helper functions such as get_text() and del_chars() to retrieve specific information required for your RPA scenario. Standard JavaScript functions can also be used to do string processing, for more information google ``javascript how to xxxx``. After reading the text content from a PDF file, TagUI will close the PDF viewer and continue with the rest of the automation steps.
  288. Using variables
  289. ********************
  290. read
  291. ###################
  292. | Gets some text or value and stores it in a variable.
  293. | Can use :ref:`DOM <dom>`, :ref:`XPath <xpath>`, :ref:`Region <region>`, :ref:`Image <image>` identifiers.
  294. .. code-block:: none
  295. read [DOM/XPath/Region/Image] to [variable]
  296. When you provide a Region or Image identifier, TagUI uses OCR (Optical Character Recognition) to read the characters from the screen.
  297. *Examples*
  298. .. code-block:: none
  299. read //p[@id="address"] to address
  300. read //p[@id="address"]/@class to address-class
  301. read (500,200)-(600,400) to id-number
  302. read frame.png to email
  303. assign
  304. ###################
  305. Saves text to a variable.
  306. .. code-block:: none
  307. [variable] = [value]
  308. | When using text in the value, surround the text in quotes, like "some text". This is actually treated by TagUI as JavaScript, so you can assign numbers to variables or use other JavaScript functions. The variable name needs to be a single word and cannot start with a number, and it is case sensitive.
  309. *Examples*
  310. .. code-block:: none
  311. count = 5
  312. username = "johncleese"
  313. fullname = firstname + lastname
  314. access
  315. ###################
  316. | To access the value of a variable in most steps, surround the variable in backticks, like `` `my_variable` ``. The following is an example of accessing a variable in the echo step.
  317. *Examples*
  318. .. code-block:: none
  319. my_variable = "hello world"
  320. echo `my_variable`
  321. // output: hello world
  322. | However, in certain steps like `if conditions <https://tagui.readthedocs.io/en/latest/main_concepts.html#if-conditions>`_, `for loops <https://tagui.readthedocs.io/en/latest/main_concepts.html#for-loops>`_ and `helper functions <https://tagui.readthedocs.io/en/latest/main_concepts.html#helper-functions>`_, the variable can be accessed directly without backticks. For more information, see docs for the relevant step.
  323. *Examples*
  324. .. code-block:: none
  325. a = "hello"
  326. b = "world"
  327. if a equals to b
  328. echo same
  329. // output:
  330. my_variable = 3
  331. for n from 1 to my_variable
  332. echo `n`
  333. // output: 1
  334. // 2
  335. // 3
  336. my_variable = "some text to copy"
  337. clipboard(my_variable)
  338. concatenation
  339. ###################
  340. | To concatenate variables, the syntax varies depending on whether you are doing so within a step. The following examples show the difference between concatenating variables within and outside the echo step.
  341. *Examples*
  342. .. code-block:: none
  343. echo `a` `b`
  344. // output: hello world
  345. a = "hello"
  346. b = "world"
  347. c = a + " " + b
  348. echo `c`
  349. // output: hello world
  350. File saving/loading
  351. ***********************
  352. .. _dump:
  353. dump
  354. #####################
  355. Saves text to a new file.
  356. .. code-block:: none
  357. dump [text] to [filename]
  358. dump [`variable`] to [filename]
  359. .. code-block:: none
  360. // creates blank CSV file with header
  361. dump First Name,Last Name to names.csv
  362. write
  363. #####################
  364. Saves a new line of text to an existing file.
  365. .. code-block:: none
  366. write [text] to [filename]
  367. write [`variable`] to [filename]
  368. *Examples*
  369. .. code-block:: none
  370. write firstname,lastname to names.csv
  371. write `fullreport` to report.txt
  372. load
  373. #####################
  374. Loads file content to a variable.
  375. .. code-block:: none
  376. load [filename] to [variable]
  377. *Examples*
  378. .. code-block:: none
  379. load report.txt to report
  380. snap
  381. ######################
  382. | Saves a screenshot of the whole page, an element or a region.
  383. | Can use :ref:`DOM <dom>`, :ref:`XPath <xpath>`, :ref:`Region <region>`, :ref:`Image <image>` identifiers.
  384. .. code-block:: none
  385. snap [DOM/XPath/Region/Image/page] to [filename]
  386. If you use ``page`` as the identifier, it takes a screenshot of the whole webpage.
  387. *Examples*
  388. .. code-block:: none
  389. snap logo to logo.png
  390. snap page to webpage.png
  391. snap (0,0)-(100,100) to image.png
  392. Showing output
  393. ********************
  394. echo
  395. ###################
  396. Shows some output on the command line.
  397. .. code-block:: none
  398. echo [text]
  399. echo [`variable`]
  400. *Examples*
  401. .. code-block:: none
  402. echo Flow has started
  403. echo The user is `username`
  404. show
  405. ###################
  406. | Shows element text directly on the command line.
  407. | Can use :ref:`DOM <dom>`, :ref:`XPath <xpath>` identifiers.
  408. .. code-block:: none
  409. show [DOM/XPath]
  410. *Examples*
  411. .. code-block:: none
  412. show review-text
  413. check
  414. ###################
  415. Shows some output on the command line based on a :ref:`condition <if-statements>`.
  416. .. code-block:: none
  417. check [condition] | [text if true] | [text if false]
  418. *Examples*
  419. .. code-block:: none
  420. check header_home_text equals to "Home" | "header text is correct" | "header text is wrong"
  421. Custom code
  422. ********************
  423. js
  424. ####################
  425. Runs JavaScript code explicitly. TagUI has direct access to the JavaScript variables.
  426. .. code-block:: none
  427. js [JavaScript statement]
  428. js begin
  429. [JavaScript statements]
  430. js finish
  431. *Examples*
  432. .. code-block:: none
  433. js obj = JSON.parse(api_result)
  434. dump `obj` to result.json
  435. js begin
  436. obj = JSON.parse(api_result)
  437. randomInteger = Math.floor(Math.random() * Math.floor(5)) + 1
  438. js finish
  439. dump `obj` to result.json
  440. // declare and initilise variable to use it inside/outside js code block
  441. a = ""
  442. js begin
  443. a = "some string"
  444. js finish
  445. echo `a`
  446. py
  447. ####################
  448. Runs Python code and saves the stdout to the variable ``py_result`` as a string.
  449. .. code-block:: none
  450. py [Python statement]
  451. py begin
  452. [Python statements]
  453. py finish
  454. *Examples*
  455. .. code-block:: none
  456. py result = 2 + 3
  457. py print(result)
  458. echo `py_result`
  459. py begin
  460. import random
  461. random_integer = random.randint(1,6)
  462. print(random_integer)
  463. py finish
  464. echo `py_result`
  465. :ref:`See this link <python>` for more examples and usage patterns on running Python code.
  466. run
  467. ####################
  468. Runs a command in Command Prompt or Terminal and saves the stdout to the variable ``run_result``.
  469. .. code-block:: none
  470. run [shell command]
  471. *Examples*
  472. .. code-block:: none
  473. run cmd /c mkdir new_directory
  474. vision
  475. ####################
  476. Runs Sikuli code.
  477. .. code-block:: none
  478. vision [Sikuli statement]
  479. vision begin
  480. [Sikuli statements]
  481. vision finish
  482. *Examples*
  483. .. code-block:: none
  484. vision click("button1.png")
  485. dom
  486. ####################
  487. Runs code in the browser dom and saves returned value to the variable ``dom_result``.
  488. .. code-block:: none
  489. dom [JavaScript statement to run in the DOM]
  490. dom begin
  491. [JavaScript statements to run in the DOM]
  492. dom finish
  493. *Examples*
  494. .. code-block:: none
  495. // goes back to previous page
  496. dom window.history.back()
  497. // returns text of an element
  498. dom return document.querySelector('#some_id').textContent
  499. r
  500. ####################
  501. Runs R statements and saves the stdout to the variable ``r_result``.
  502. .. code-block:: none
  503. r [R statement]
  504. r begin
  505. [R statements]
  506. r finish
  507. Miscellaneous
  508. ********************
  509. wait
  510. ####################
  511. Explicitly wait for some time.
  512. .. code-block:: none
  513. wait [seconds to wait]
  514. wait [seconds to wait] s
  515. wait [seconds to wait] seconds
  516. *Examples*
  517. .. code-block:: none
  518. wait 5.5
  519. wait 10 s
  520. wait 20 seconds
  521. timeout
  522. ####################
  523. Changes the auto-wait timeout when waiting for web elements to appear (default 10 seconds).
  524. .. code-block:: none
  525. timeout [seconds to wait before timeout]
  526. *Examples*
  527. .. code-block:: none
  528. timeout 300
  529. ask
  530. ####################
  531. Prompts user for input and saves the input as the variable ``ask_result``.
  532. .. code-block:: none
  533. ask [prompt]
  534. *Examples*
  535. .. code-block:: none
  536. ask What is the date of the receipt? (in DD-MM-YYYY)
  537. type search as `ask_result`
  538. live
  539. ###################
  540. Run steps interactively and immediately see the output. The user must enter "done" before the flow continues.
  541. .. code-block:: none
  542. live
  543. tagui
  544. ####################
  545. Runs another TagUI flow. Checks the flow's folder.
  546. .. code-block:: none
  547. tagui [flow file]
  548. tagui [folder/flow file]
  549. *Examples*
  550. .. code-block:: none
  551. tagui update-forex.tag
  552. tagui flows/update-forex.tag
  553. comment
  554. ###################
  555. Adds a comment. If you are inside a code block, for example an if condition or for loop, be sure to indent your comment accordingly to let TagUI run correctly after it converts into JavaScript code.
  556. .. code-block:: none
  557. // [comment]
  558. *Examples*
  559. .. code-block:: none
  560. // updates the forex rates
  561. telegram
  562. ###################
  563. Sends a Telegram notification, for example, to update on automation completion or exception.
  564. First, message `@taguibot <https://t.me/taguibot>`_ to authorise it to send messages to your Telegram. Then in TagUI:
  565. .. code-block:: none
  566. telegram [id] [message]
  567. *Examples*
  568. .. code-block:: none
  569. // this line sends message to Telegram user with ID 1234567890, \n means a new line
  570. telegram 1234567890 Hello Alena,\n\nYour HR onboarding bot has completed successfully.
  571. // show telegram_result variable - 'success' means sent, 'fail' means sending failed
  572. echo Telegram message - `telegram_result`
  573. // if condition to check telegram_result 'success' or 'fail' and handle accordingly
  574. if telegram_result equals to 'success'
  575. echo Message sent successfully.
  576. else
  577. echo Message sending failed.
  578. Note that the telegram step requires an internet connection. This feature is being hosted at https://tebel.org, but the `source code <https://github.com/kelaberetiv/TagUI/tree/master/src/telegram>`_ is on GitHub if you wish to host this feature on your own cloud or server. The implementation is in pure PHP without any dependencies.
  579. The only info logged is chat_id, length of the message, datetime stamp (to prevent abuse). If you wish to host on your own, first read through this link to learn more about Telegram Bot API, creating your bot API token and setting up the webhook - https://core.telegram.org/bots
  580. Run options
  581. ----------------------
  582. You can use the below options when running ``tagui``.
  583. For example, the command below runs ``my_flow.tag`` without showing the web browser, while storing the flow run result in ``tagui_report.csv``. ::
  584. tagui my_flow.tag -headless -report
  585. -deploy or -d
  586. ********************
  587. Deploys a flow, creating a shortcut which can be double-clicked to run the flow. If the flow file is moved, a new shortcut must be created. The flow will be run with all the options used when creating the shortcut.
  588. -headless or -h
  589. ********************
  590. Runs the flow with an invisible Chrome web browser (does not work for visual automation).
  591. -nobrowser or -n
  592. ********************
  593. Runs without any web browser, for example to perform automation only with visual automation.
  594. -report or -r
  595. ********************
  596. Tracks flow run result in ``tagui/src/tagui_report.csv`` and saves html logs of flows execution.
  597. -turbo or -t
  598. ********************
  599. Run automation at 10X the speed of normal human user. Read caveats at Advanced concepts!
  600. -quiet or -q
  601. ********************
  602. Runs without output to command prompt except for explicit output (echo, show, check steps and errors etc). To have fine-grained control on showing and hiding output during execution (eg hiding password from showing up), use ``quiet_mode = true`` and ``quiet_mode = false`` in your flow.
  603. -edge or -e
  604. ********************
  605. Runs using Microsoft Edge browser instead of Chrome (can be used with -headless option).
  606. my_datatable.csv
  607. ********************
  608. Uses the specified csv file as the datatable for batch automation. See :ref:`datatables <datatables>`.
  609. input(s)
  610. ********************
  611. Add your own parameter(s) to be used in your automation flow as variables p1 to p8.
  612. For example, from the command prompt, below line runs ``register_attendence.tag`` workflow using Microsoft Edge browser and with various student names as inputs. ::
  613. tagui register_attendence.tag -edge Jenny Jason John Joanne
  614. Inside the workflow, the variables ``p1``, ``p2``, ``p3``, ``p4`` will be available for use as part of the automation, for example to fill up student names into a web form for recording attendence. The following lines in the workflow will output various student names given as inputs. ::
  615. echo `p1`
  616. echo `p2`
  617. echo `p3`
  618. echo `p4`
  619. See :doc:`other deprecated options </dep_options>`.
  620. .. _helper-functions-reference:
  621. Helper functions
  622. --------------------
  623. csv_row()
  624. ********************
  625. Formats an array for writing to csv file.
  626. *Examples*
  627. .. code-block:: none
  628. read name_element to name
  629. read price_element to price
  630. read details_element to details
  631. write `csv_row([name, price, details])` to product_list.csv
  632. count()
  633. ********************
  634. Gets the number of elements matching the identifier specified. Note that the identifier needs to be in single quotes ``''``.
  635. *Examples*
  636. .. code-block:: none
  637. rows = count('table-rows')
  638. clipboard()
  639. ********************
  640. Puts text onto the clipboard, or gets the clipboard text (if no input is given).
  641. *Examples*
  642. .. code-block:: none
  643. clipboard('some text')
  644. keyboard [ctrl]v
  645. keyboard [ctrl]c
  646. contents = clipboard()
  647. url()
  648. ********************
  649. Gets the URL of the current web page.
  650. *Examples*
  651. .. code-block:: none
  652. if url() contains 'success'
  653. click button1
  654. title()
  655. ********************
  656. Gets the title of the current web page.
  657. *Examples*
  658. .. code-block:: none
  659. if title() contains 'Confirmation'
  660. click button1
  661. text()
  662. ********************
  663. Gets all text content of the current web page.
  664. *Examples*
  665. .. code-block:: none
  666. if text() contains 'success'
  667. click button1
  668. timer()
  669. ********************
  670. Gets the time elapsed in seconds in between each running of this function.
  671. *Examples*
  672. .. code-block:: none
  673. timer()
  674. click button1
  675. click button2
  676. click button3
  677. echo `timer()`
  678. .. _exist:
  679. exist()
  680. ********************
  681. | Waits until the timeout for an element to exist and returns a JavaScript ``true`` or ``false`` depending on whether it exists or not.
  682. | Note that the identifier is surrounded by quotes.
  683. | Can use :ref:`DOM <dom>`, :ref:`XPath <xpath>`, :ref:`Image <image>` identifiers.
  684. .. code-block:: none
  685. exist('[DOM/XPath/Image]')
  686. *Examples*
  687. .. code-block:: none
  688. if exist('//table')
  689. click button1
  690. present()
  691. ********************
  692. | Same as :ref:`exist() <exist>` except that it does not wait until the timeout and immediately returns ``true`` or ``false``.
  693. | Note that the identifier is surrounded by quotes.
  694. | Can use :ref:`DOM <dom>`, :ref:`XPath <xpath>`, :ref:`Image <image>` identifiers.
  695. *Examples*
  696. .. code-block:: none
  697. if present('//table')
  698. click button1
  699. mouse_xy()
  700. ********************
  701. | Gets the x, y coordinates of the current mouse position.
  702. | Particularly useful in :ref:`live mode <live-mode>`.
  703. *Examples*
  704. .. code-block:: none
  705. echo `mouse_xy()`
  706. mouse_x()
  707. ********************
  708. Gets the x coordinate of the current mouse position as a number, eg 200.
  709. *Examples*
  710. .. code-block:: none
  711. hover element.png
  712. x = mouse_x() + 200
  713. y = mouse_y()
  714. click (`x`,`y`)
  715. mouse_y()
  716. ********************
  717. Gets the y coordinate of the current mouse position as a number, eg 200.
  718. *Examples*
  719. .. code-block:: none
  720. hover element.png
  721. x = mouse_x() + 200
  722. y = mouse_y()
  723. click (`x`,`y`)
  724. get_files()
  725. ********************
  726. Returns an array of files and folders in a given folder. Both relative and absolute paths supported.
  727. *Examples*
  728. .. code-block:: none
  729. // list of files in the same folder as the flow file
  730. list = get_files('.')
  731. // list of files in the Desktop folder of user Alan
  732. // note double backslash because of JavaScript string
  733. list = get_files('C:\\Users\\Alan\\Desktop')
  734. // alternatively, use single forward slash instead
  735. list = get_files('C:/Users/Alan/Desktop')
  736. // showing the list of files after retrieving it
  737. // JavaScript array start from 0 for 1st element
  738. for n from 0 to list.length-1
  739. echo `list[n]`
  740. // checking to process a specific file extension
  741. for n from 0 to list.length-1
  742. if list[n] contains '.XLSX'
  743. echo `list[n]`
  744. get_text()
  745. ********************
  746. Extracts text between 2 provided anchors from given text. Optional 4th parameter for occurrence during multiple matches (for example 3 to tell the function to return the 3rd match found).
  747. *Examples*
  748. .. code-block:: none
  749. pdf_text = 'Name: John State: Texas City: Plano Contact: ...'
  750. name = get_text(pdf_text, 'Name:', 'State:')
  751. state = get_text(pdf_text, 'State:', 'City:')
  752. city = get_text(pdf_text, 'City:', 'Contact:')
  753. echo `name`, `state`, `city`
  754. del_chars()
  755. ********************
  756. Cleans data by removing provided character(s) from given text and returning the result.
  757. *Examples*
  758. .. code-block:: none
  759. pdf_text = 'Name: John\n State: Texas\t City: Plano\n Contact: ...'
  760. echo `del_chars(pdf_text, '\n\t:')`
  761. get_env()
  762. ********************
  763. Returns the value of given environment variable from the operating system.
  764. *Examples*
  765. .. code-block:: none
  766. // getting %USERPROFILE% variable for Windows
  767. echo `get_env('USERPROFILE')`
  768. home_dir = get_env('USERPROFILE')
  769. // getting $HOME variable for Mac or Linux
  770. echo `get_env('HOME')`
  771. home_dir = get_env('HOME')