When using pywinauto, many friends will encounter problems that they cannot perform operations such as menus for Chinese applications. In fact, this is only caused by encoding.
There are two ways to solve this problem:
- The first method is to convert a string in UTF format using "U:
............
Edit_name = U ' Save webpage '
Save_name = U ' Save (& S) '
Ask_name = U ' Save webpage '
Yes_name = U ' Yes (& Y) '
............
app = application (). start _ (r " C: \ Program Files \ Internet Explorer \ iexplore.exe % S " % web_addresss)
time. sleep ( 1 )
ie = app. window _ (title_re = " . * Microsoft Internet Explorer. * " )
Print " no menu's in IE: " , ie. menuitems ()
Print " they are implemented as a toolbar: " , ie. toolbar3.texts ()
Ie. typekeys ("% Fa")
Savewebpage=APP [edit_name]
Savewebpage ['Edit']. Setedittext (OS. Path. Join (R"C: \. Temp", Outputfilename ))
............
- The second method is to use the decode function to forcibly convert the string encoding:
............
CP = 'cp936'
Edit_name = 'Save webpage '. Decode (CP)
Save_name = 'Save (& S) '. Decode (CP)
Ask_name = 'Save webpage '. Decode (CP)
Yes_name = 'Yes (& Y)'. Decode (CP)
............
App=Application (). Start _ (R"C: \ Program Files \ Internet Explorer \ iexplore.exe % s"%Web_addresss)
Time. Sleep (1)
ie = app. window _ (title_re = " . * Microsoft Internet Explorer. * " )
Print " no menu's in IE: " , ie. menuitems ()
Print " they are implemented as a toolbar: " , ie. toolbar3.texts ()
Ie. typekeys ("% Fa")
Savewebpage=APP [edit_name]
Savewebpage ['Edit']. Setedittext (OS. Path. Join (R"C: \. Temp", Outputfilename ))
............