Roy Jaques
Roy Jaques

Reputation: 121

changing the text in a toolbar with pywinauto

I have a file selection window from an windows application I'm trying to automate.

enter image description here

I can change the File name box at the bottom by using

app2.window(title_re='Select a batch file') \
            .File_name_Edit.set_text(selected_filename)

I have previously entered the full filepath and filename in to the lower box, however, it will no longer accept slashes in the File name box after a windows update. Hence the problem.

So the problem is the top (directory/folder name) box.

Manually I can select the box, highlight it then overtype the directory.

I cannot find a way to do this using pywinauto.

Methods attempted are:

toolbar2 = app2.window(title_re='Select a batch file')  # \
#     .child_window(title_re='Address', auto_id='1001')
#     .child_window(title_re='Address', control_type="ToolBar", auto_id='1001')
file_path_address = toolbar2['Address band toolbarToolbar'].click_input()
file_path_address.set_text(directory_path)

# ToolbarWrapper(toolbar2).set_text(directory_path)
# ToolbarWrapper(toolbar2).click(button='All locationsSplitButton').set_text(directory_path)
# ToolbarWrapper(toolbar2)['Address:'].set_text(directory_path)

I'm using set_text as the automation must run behind a locked screen, type_keys does not work with a locked screen as type_keys is a keyboard method and Windows blocks keyboard entry when the screen is locked.

I have no access to the internals of the program being automated in order to change the original directory path and need to change it to read in from a different location.

Any assistance would be appreciated.

Upvotes: 0

Views: 1789

Answers (2)

ahmed zain
ahmed zain

Reputation: 11

you can use right click then edit the field

toolbar2['Address band toolbarToolbar'].click_input(button="right")
app2.PopupMenu.child_window(title="Edit address", control_type="MenuItem").click_input()
app2.child_window(title="Address", control_type="Edit").set_edit_text(directory_path)

Upvotes: 1

Sachin
Sachin

Reputation: 171

See below code, It runs fine with Notepad++ on Win 10

import time
from pywinauto.application import Application

app = Application().Connect(title=u'Open', class_name='#32770')
window = app.Dialog

toolbarwindow = window.Toolbar3
toolbarwindow.Click()
time.sleep(0.30)

static = window.Edit2
directory_path = "C:\Users\Desktop"

raw_directory_path = r'{}'.format(directory_path)
static.set_edit_text(text = raw_directory_path)
static.type_keys("{ENTER}")

Upvotes: 1

Related Questions