Pywinauto - Control Identifiers disappear when running the same command - python-3.x

I'm looking at control identifiers to create an automation script and noticed that the first time I ran print_control_identifiers(), I had DataItems that showed up. However, any time after that when running the same print_control_identifiers() command, all the controls showed up except for the DataItems.
Code:
app = Application(backend="uia").connect(best_match="ARMOR CRITICAL")
app.window(control_type="Window").child_window(control_type="Document").print_control_identifiers()
Output - first pass
Output - second pass
I've been using the uia backend every time.
I'm using Python 3.7.4 and pywinauto 0.6.8

Related

Python Selenium Remote Webdriver Upload File

I am using python 3.9 and selenium 4.6.0 on Chrome. I have a script that needs to upload a file to an input, this works fine on local but fails when run on RemoteDriver. The code I am using is
driver.find_element(By.XPATH, "//input[#accept]").send_keys('path to file')
When run on RemoteDriver the error returned is
selenium.common.exceptions.WebDriverException: Message: unknown command: unknown command: session/cddd71e067d7717481fb8a635103c643/se/file
I've think it is due to this line in the remote_connection.py file in selenium
Command.UPLOAD_FILE: ('POST', "/session/$sessionId/se/file")
From the research I've done the 'se' in this case is a 'vendor_prefix' for selenium but I cannot figure out how to either configure the remote driver to use a vendor prefix or remove that from POST path that is being passed (short of pulling my own version of the code and maintaining that).
For other functional reasons I can't revert to selenium 3x (which is an option I've seen to correct this), nor can I set w3c to False. Does anyone know how to work around this particular issue; either by getting send_keys to operate as expected in this situation or using another method to upload the file? Thanks.

Why pandas profiling isn't showing any output in ipython?

I've a quick question about "pandas_profiling" .So basically i'm trying to use the pandas 'profiling' but instead of showing the output it says something like this:
<pandas_profiling.ProfileReport at 0x23c02ed77b8>
Where i'm making the mistake?? or Does it have anything to do with Ipython?? Because i'm using Ipython in Anaconda.
try this
pfr = pandas_profiling.ProfileReport(df)
pfr.to_notebook_iframe()
pandas_profiling creates an object that then needs to be displayed or output. One standard way of doing so is to save it as an HTML:
profile.to_file(outputfile="sample_file_name.html")
("profile" being the variable you used to save the profile itself)
It doesn't have to do with ipython specifically - the difference is that because you're going line by line (instead of running a full block of code, including the reporting step) it's showing you the object itself. The code above should allow you to see the report once you open it up.

debug python code and change variables at runtime in pyCharm

I am using pycharm to 2018.3.4 to develop python scripts and I am still pretty new in this language, I normally write PowerShell code. I have a question concerning debugging. Take this unfinished code as an example.
#! python3
# phoneAndEmail.py - Finds phone numbers and email addresses on the clipboard.
import pyperclip, re, sys
phoneRegex = re.compile(r'''(
(\(?([\d \-\)\–\+\/\(]+)\)?([ .-–\/]?)([\d]+))
)''', re.VERBOSE)
mailRegex = re.compile(r'''(
\w+#\w+\.\w+
)''', re.VERBOSE)
text = pyperclip.paste()
def getMatches(text, regex) :
return regex.findall(text)
Emails = getMatches(text,mailRegex) #I want to play with this variable at runtime
phone = getMatches(text,phoneRegex)
I am at the stage where I want to analyze the variable Emails at runtime. So I set a breakpoint and can view the contents of the varieble just fine. However I also want to run some methods and play with their input parameters at runtime. Does someone know how this is possible? If this is possible with another IDE then this would be fine too.
In Pycharm 2018.3.4 you simply do this by clicking on the console tab and then on the show command prompt button.
Now you can type in Emails or Emails.pop() for example in order to manipulate variables:
You can also refer to this post, where this was discussed for an older version: change variable in Pycharm debugger

pyldavis Unable to view the graph

I am trying to visually depict my topics in python using pyldavis. However i am unable to view the graph. Is it that we have to view the graph in the browser or will it get popped upon execution. Below is my code
import pyLDAvis
import pyLDAvis.gensim as gensimvis
print('Pyldavis ....')
vis_data = gensimvis.prepare(ldamodel, doc_term_matrix, dictionary)
pyLDAvis.display(vis_data)
The program is continuously in execution mode on executing the above commands. Where should I view my graph? Or where it will be stored? Is it integrated only with the Ipython notebook?Kindly guide me through this.
P.S My python version is 3.5.
This not work:
pyLDAvis.display(vis_data)
This will work for you:
pyLDAvis.show(vis_data)
I'm facing the same problem now.
EDIT:
My script looks as follows:
first part:
import pyLDAvis
import pyLDAvis.sklearn
print('start script')
tf_vectorizer = CountVectorizer(strip_accents = 'unicode',stop_words = 'english',lowercase = True,token_pattern = r'\b[a-zA-Z]{3,}\b',max_df = 0.5,min_df = 10)
dtm_tf = tf_vectorizer.fit_transform(docs_raw)
lda_tf = LatentDirichletAllocation(n_topics=20, learning_method='online')
print('fit')
lda_tf.fit(dtm_tf)
second part:
print('prepare')
vis_data = pyLDAvis.sklearn.prepare(lda_tf, dtm_tf, tf_vectorizer)
print('display')
pyLDAvis.display(vis_data)
The problem is in the line "vis_data = (...)".if I run the script, it will print 'prepare' and keep on running after that without printing anything else (so it never reaches the line "print('display')).
Funny thing is, when I just run the whole script it gets stuck on that line, but when I run the first part, got to my console and execute purely the single line "vis_data = pyLDAvis.sklearn.prepare(lda_tf, dtm_tf, tf_vectorizer)" this is executed in a couple of seconds.
As for the graph, I saved it as html ("simple") and use the html file to view the graph.
I ran into the same problem (I use PyCharm as IDE) The problem is that pyLDAvize is developed for Ipython (see the docs, https://media.readthedocs.org/pdf/pyldavis/latest/pyldavis.pdf, page 3).
My fix/workaround:
make a dict of lda_tf, dtm_tf, tf_vectorizer (eg., pyLDAviz_dict)dump the dict to a file (eg mydata_pyLDAviz.pkl)
read the pkl file into notebook (I did get some depreciation info from pyLDAviz, but that had no effect on the end result)
play around with pyLDAviz in notebook
if you're happy with the view, dump it into html
The cause is (most likely) that pyLDAviz expects continuous user interaction (including user-initiated "exit"). However, I rather dump data from a smart IDE and read that into jupyter, than develop/code in jupyter notebook. That's pretty much like going back to before-emacs times.
From experience this approach works quite nicely for other plotting rountines
If you received the module error pyLDA.gensim, then try this one instead:
import pyLdAvis.gensim_models
You get the error because of a new version update.

Can not make DDE connection using python. win32ui appears not working

I am new to Python (version 2.7). I have been using for a long time some excel workbooks that uses DDE function to capture "real-time market data" - that is served by one Market Data Provider ("Matriks", if matters).
In a bit to simplify my overall process flow, I decided to bypass this excel workbook thing for data capture, and instead, I decided to use python codes to perform the same task.
The problem is that,
1) I get "error: The server could not be created" when I run the code (provided below) using Pythonwin.
2) and I get "ImportError: This must be an MFC application - try 'import win32ui' first" when I run this very simple code using IDLE.
(and of course, I downloaded and run win32ui.)
Any help is appreciated.
# DDE code
# excel equivalent of this code is: =MTX|DATA!EURUSD.SON
import win32ui
import dde
s=dde.CreateServer()
s.Create("MTX")
c=dde.CreateConversation(s)
c.ConnectTo("DATA","SON")
c.Connected()
c.Request("EURUSD")
# returns
# Traceback (most recent call last):
# File "C:\IQTrader\_script\_obj\DDEClient.py", line 12, in <module>
# import dde
# ImportError: This must be an MFC application - try 'import win32ui' first
The issue is resolved. The very basic reason for the error is the pywin module.
For those facing with the same problem:
1.Delete pythonwin and pywin32_system32 folderes entirely (presumably under C:\Python27\Lib\site-packages)
2.Check your pywin32 version; it should be 214 (not 218) for those using v2.7
3.Download pywin32-214.win32-py2.7 from appropriate resources (one is this: http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/ )
4.Everything should be fine.
I had a similar problem. I had to:
uninstall Python 2.7 64-bit
install Python 2.7 32-bit
use the pywin32 version 214
Run cmd.exe as administrator so that the c.ConnectTo() connects successfully
However, I am still having the weird problem that I must have Excel open at the same time with a cell holding the value =MTX|DATA!EURUSD.SON for the python script to return a valid quote. Otherwise, I just get "N/A" as the return value.
#Aykut did you run into this issue as well?

Resources