Skip to content

Commit 28b253a

Browse files
committed
#31 #32 #24 - ask() in Chrome browser if available
#31 - ask() shows the question in terminal window. This is not intuitive if automation is running on the Chrome browser and a prompt appears in terminal window to ask for user input. Raising an issue to update behaviour to show prompt in Chrome browser, if it's available. PS - similar issue exists if chrome_browser = False and visual_automation = True. The terminal may not be in the foreground during the automation flow to be visible for user inputs. However, there isn't a consistent way to show SikuliX popup with focus across platforms. Thus KIV for now. #32 - At present, if visual automation mode is not on and `snap('page.png', 'screenshot.png')` is used, there is no error message saying that `init(visual_automation = True)` is needed to use this. Raising an issue to show error message instead of hanging waiting for SikuliX response. #24 - readme linking to RedMart online groceries example to automate re-adding all items to cart (to reschedule delivery, need to cancel and create new order manually)
1 parent 4198e0e commit 28b253a

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

README.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ t.close()
7777

7878
# API Reference
7979

80-
[See sample Python script](https://github.com/tebelorg/TagUI-Python/blob/master/sample.py). For web automation, web element identifier can be XPath selector, CSS selector or the following attributes - id, name, class, title, aria-label, text(), href (in decreasing order of priority). There is automatic waiting for an element to appear before timeout happens, and error is returned that the element cannot be found. To change the default timeout of 10 seconds, use timeout() function.
80+
Check out [sample Python script](https://github.com/tebelorg/TagUI-Python/blob/master/sample.py) and [RedMart groceries example](https://github.com/tebelorg/TagUI-Python/issues/24).
8181

82-
An element identifier can also be a .png or .bmp image snapshot representing the UI element (can be on desktop applications or web browser). x, y coordinates of elements on the screen work as well. Transparency (0% opacity) is supported in .png images, for eg using an image of an UI element with transparent background to enable clicking on an UI element that appears on different backgrounds on different occasions.
82+
- For web automation, web element identifier can be XPath selector, CSS selector or the following attributes - id, name, class, title, aria-label, text(), href (in decreasing order of priority). There is automatic waiting for an element to appear before timeout happens, and error is returned that the element cannot be found. To change the default timeout of 10 seconds, use timeout() function.
8383

84-
A further example is an image of the window or frame (PDF viewer, MS Word, textbox etc) with the center content of the image set as transparent. This allows using read() and snap() to perform OCR and save snapshots for application windows, containers, frames, textboxes with varying content. Also for read() and snap(), x1, y1, x2, y2 coordinates pair can be used to define the region of interest on the screen to perform OCR or capture snapshot.
84+
- An element identifier can also be a .png or .bmp image snapshot representing the UI element (can be on desktop applications or web browser). x, y coordinates of elements on the screen work as well. Transparency (0% opacity) is supported in .png images, for eg using an image of an UI element with transparent background to enable clicking on an UI element that appears on different backgrounds on different occasions.
85+
86+
- A further example is an image of the window or frame (PDF viewer, MS Word, textbox etc) with the center content of the image set as transparent. This allows using read() and snap() to perform OCR and save snapshots of application windows, containers, frames, textboxes with varying content. Also for read() and snap(), x1, y1, x2, y2 coordinates pair can be used to define the region of interest on the screen to perform OCR or capture snapshot.
8587

8688
#### CORE FUNCTIONS
8789
Function|Parameters|Purpose
@@ -99,7 +101,7 @@ send()|tagui_instruction|send TagUI instruction to TagUI for execution
99101
#### BASIC FUNCTIONS
100102
Function|Parameters|Purpose
101103
:-------|:---------|:------
102-
url()|webpage_url (blank to return current URL)|go to web URL
104+
url()|webpage_url (no parameter to return current URL)|go to web URL
103105
click()|element_identifier (or x, y using visual automation)| left-click on element
104106
rclick()|element_identifier (or x, y using visual automation)|right-click on element
105107
dclick()|element_identifier (or x, y using visual automation)|double-click on element
@@ -111,7 +113,7 @@ snap()|element_identifier (page = web page), filename_to_save|save screenshot to
111113
load()|filename_to_load|load & return file content
112114
dump()|text_to_dump, filename_to_save|save text to file
113115
write()|text_to_write, filename_to_save|append text to file
114-
echo()|text_to_echo|print text to output
116+
echo()|text_to_echo|print text to screen
115117
ask()|text_to_prompt|ask & return user input
116118

117119
#### PRO FUNCTIONS
@@ -128,9 +130,9 @@ unzip()|file_to_unzip, unzip_location (optional)|unzip zip file to specified loc
128130
run()|command_to_run (; between commands)|run OS command & return output
129131
dom()|statement_to_run (JavaScript code)|run code in DOM & return output
130132
vision()|command_to_run (Python code)|run custom SikuliX commands
131-
timeout()|timeout_in_seconds (blank to return current timeout)|change wait timeout (default 10s)
133+
timeout()|timeout_in_seconds (blank returns current timeout)|change wait timeout (default 10s)
132134

133-
**keyboard() modifiers and special keys**
135+
**keyboard() - modifiers and special keys**
134136
>[shift] [ctrl] [alt] [cmd] [win] [meta] [clear] [space] [enter] [backspace] [tab] [esc] [up] [down] [left] [right] [pageup] [pagedown] [delete] [home] [end] [insert] [f1] .. [f15] [printscreen] [scrolllock] [pause] [capslock] [numlock]
135137
136138
#### HELPER FUNCTIONS

sample.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Sample script to search github on Yahoo, capture screenshot of results and visit DuckDuckgo
12
# TagUI for Python's simple, expressive and powerful API makes digital automation fun and easy!
23
# pip install tagui to install TagUI for Python, pip install tagui --upgrade for latest version
34

@@ -51,12 +52,10 @@
5152
# also supports visual element identifier using .png or .bmp image snapshot
5253
# representing the UI element (can be on desktop applications or web browser)
5354
# for eg t.click('start_menu.png'), t.type('username_box.png', 'Sonic')
54-
5555
# image transparency (0% opacity) is supported, ie images with empty sections
5656
# t.read('image_preview_frame.png'), t.snap('application_window_frame.png')
5757

5858
# visual element identifiers can also be x, y coordinates of elements on the screen
5959
# for eg t.click(600, 300), t.type(600, 300, 'Mario'), t.select(600, 300, 600, 400)
60-
6160
# another eg is limits of area of interest x1, y1, x2, y2 for read() and snap()
6261
# t.read(200, 200, 600, 400), t.snap(200, 200, 600, 400, 'results.png')

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
setup(
44
name='tagui',
5-
version='1.7.0',
5+
version='1.8.0',
66
py_modules=['tagui'],
77
author='Ken Soh',
88
author_email='[email protected]',
99
license='Apache License 2.0',
1010
url='https://github.com/tebelorg/TagUI-Python',
1111
description='TagUI for Python is a Python package for digital process automation (RPA)',
12-
long_description='TagUI for Python documentation here - https://github.com/tebelorg/TagUI-Python',
12+
long_description='TagUI for Python homepage - https://github.com/tebelorg/TagUI-Python',
1313
classifiers=[
1414
'Development Status :: 4 - Beta',
1515
'Programming Language :: Python :: 2',

tagui.py

+25-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""INTEGRATION ENGINE FOR TAGUI PYTHON PACKAGE ~ TEBEL.ORG"""
22
__author__ = 'Ken Soh <[email protected]>'
3-
__version__ = '1.7.0'
3+
__version__ = '1.8.0'
44

55
import subprocess
66
import os
@@ -659,7 +659,12 @@ def exist(element_identifier = None):
659659
return False
660660

661661
# return True for keywords as the computer screen always exists
662-
if element_identifier.lower() in ['page.png', 'page.bmp']: return True
662+
if element_identifier.lower() in ['page.png', 'page.bmp']:
663+
if _visual():
664+
return True
665+
else:
666+
print('[TAGUI][ERROR] - page.png / page.bmp requires init(visual_automation = True)')
667+
return False
663668

664669
# pre-emptive check for existence of specified image file for visual automation
665670
if element_identifier.lower().endswith('.png') or element_identifier.lower().endswith('.bmp'):
@@ -840,7 +845,7 @@ def select(element_identifier = None, option_value = None, test_coordinate1 = No
840845
return False
841846

842847
if element_identifier.lower() in ['page.png', 'page.bmp'] or option_value.lower() in ['page.png', 'page.bmp']:
843-
print('[TAGUI][ERROR] - page.png and page.bmp invalid for select()')
848+
print('[TAGUI][ERROR] - page.png / page.bmp identifiers invalid for select()')
844849
return False
845850

846851
if test_coordinate1 is not None and test_coordinate2 is not None and \
@@ -986,15 +991,19 @@ def write(text_to_write = None, filename_to_save = None):
986991
return True
987992

988993
def ask(text_to_prompt = ''):
989-
if text_to_prompt == '':
990-
space_padding = ''
991-
else:
992-
space_padding = ' '
994+
if _chrome():
995+
return dom("return prompt('" + _esq(text_to_prompt) + "')")
993996

994-
if _python2_env():
995-
return raw_input(text_to_prompt + space_padding)
996997
else:
997-
return input(text_to_prompt + space_padding)
998+
if text_to_prompt == '':
999+
space_padding = ''
1000+
else:
1001+
space_padding = ' '
1002+
1003+
if _python2_env():
1004+
return raw_input(text_to_prompt + space_padding)
1005+
else:
1006+
return input(text_to_prompt + space_padding)
9981007

9991008
def keyboard(keys_and_modifiers = None):
10001009
if not _started():
@@ -1218,7 +1227,12 @@ def present(element_identifier = None):
12181227
return False
12191228

12201229
# return True for keywords as the computer screen is always present
1221-
if element_identifier.lower() in ['page.png', 'page.bmp']: return True
1230+
if element_identifier.lower() in ['page.png', 'page.bmp']:
1231+
if _visual():
1232+
return True
1233+
else:
1234+
print('[TAGUI][ERROR] - page.png / page.bmp requires init(visual_automation = True)')
1235+
return False
12221236

12231237
# check for existence of specified image file for visual automation
12241238
if element_identifier.lower().endswith('.png') or element_identifier.lower().endswith('.bmp'):

0 commit comments

Comments
 (0)