I am working on an automation program to review/test content within a third party application. At the moment Im going with pyautogui to highlight and copy values(at least until we get access to query the applications database) and tkinter to retrieve data from the clipboard.
The script below has worked in copying content that can be highlighted on the screen (under the #get manager section in the script).
However, when I navigate to a section that has a text body (#QAR test 2), use pyautogui.hotkey("Ctrl","a") to highlight all and pyautogui.hotkey("Ctrl","c") to copy, it seems like the clipboard is not populated (due to the error message when trying to print out the variable it has been assigned to).
For reference, I am attaching a screen shot of the target text. Can text (specifically, paragraphs) not be copied over to the clipboard?
The error message raised after the #QAR Test 2 is:
Traceback (most recent call last):
File "C:/Users/haudrxr/Downloads/PCA_5_5_18_QAR.py", line 92, in <module>
background_tm= copy_clipboard()
File "C:/Users/haudrxr/Downloads/PCA_5_5_18_QAR.py", line 10, in copy_clipboard
clipboard = Tk().clipboard_get()
File "C:\Users\haudrxr\AppData\Local\Continuum\anaconda3\lib\tkinter\__init__.py", line 804, in clipboard_get
return self.tk.call(('clipboard', 'get') + self._options(kw))
_tkinter.TclError: CLIPBOARD selection doesn't exist or form "STRING" not defined
...
#Get Manager Value
x=115
y=450
for i in range (10):
pyautogui.click(x, y)
time.sleep(1)
pyautogui.doubleClick(839, 567)
pyautogui.hotkey("Ctrl","c")
level=copy_clipboard()
y += 23
if level=="1":
pyautogui.mouseDown(750, 437,button="left",duration=1)
pyautogui.dragTo(1049, 437,1, button='left')
pyautogui.hotkey("Ctrl", "c")
staffname = copy_clipboard()
if len(staffname)>1:
team_tab.append(staffname)
print(team_tab)
else:
continue
team_tab = list(filter(None, team_tab)) # fastest
print(len(team_tab))
if len(team_tab)>2:
print("QAR Item 1: PASS")
else:
print("QAR Item 1: FAIL")
#QAR Test 2
if windll.user32.OpenClipboard(None):
windll.user32.EmptyClipboard()
windll.user32.CloseClipboard()
pyautogui.click(262, 162) # navigates to tab with text box
pyautogui.click(614, 314) #clicks in text box
pyautogui.hotkey("Ctrl", "a")
pyautogui.hotkey("Ctrl", "c")
background_tm= copy_clipboard()
time.sleep(10)
print(background_tm)
print("test1")