Check if send_keys is sending the key? - python

I am trying to set-up a condition where the script checks whether a web element is present or not. If present, actions.send_keys(Keys.ESCAPE).
if len(str(driver.find_element_by_class_name("blnewform_wrapper"))) >0:
actions.send_keys(Keys.ESCAPE)
print("I sent escape")
else:
print("Didn't find the form")
print(count)
I get an output:
I sent escape
But the form is still in the forefront. When I click escape on the page it exits. So I am just wondering how exactly to check whether the ESCAPE key is being sent or not.

You have not performed the actions, replace:
actions.send_keys(Keys.ESCAPE)
with:
actions.send_keys(Keys.ESCAPE).perform()
As far as making sure it was sent - send_keys() would throw an error if an element you are sending keys to is not interactable (usually that means not visible or disabled). You may also recheck the visibility of the form after sending the keys.

Related

FIX Protocol : 35=8 Execution Report coming in log file but not passing through fromApp()/onMessage()

I am sending the below FIX sample message using the quickfix python library.
8=FIX4.4,9=225,35=D,34=3,49=AB,52=20220919-07:43:13.917,56=CD,11=44536,15=EUR,17=00002,21=3,37=44536,38=918293,40=2,44=0,48=11,54=1,55=EURUSD,58=LKLA,
59=0,60=20220919-07:43:13.917,64=20220921,78=1,79=LKLA,80=918293,448=f88f2f6277,10=097
Immediately after sending the message, I am getting the message back from the server with 35=8 tag. Please see the below the message
8=FIX4.4,9=201,35=8,49=CD,56=AB,34=2,52=20220919-07:56:05.330,11=44536,15=EUR,38=918293,40=2,54=1,55=EURUSD,59=0,64=20220921,
6=0.,14=0,17=5249952-1024823399,31=0.,32=0,37=5249952-1024823399,39=0,150=0,151=918293,10=047
(tags 35=Execution report, 39= New, 150 = New)
When the trade is executed in FXALL, and when I send new FIX messages again, All the executed trades are logged in messages.current.log file. I am getting the below message in log file but not in fromApp.
8=FIX4.4,9=520,35=8,49=CD,56=AB,34=3,52=20220919-11:24:03.145,39=2,37=152648401_0_0,11=44536,17=152648401_0_0,150=F,1=test#bc,64=20220921,55=EUR/USD,40=1,15=EUR,31=0.9997,194=0.9997,195=0.,151=0,6=0.9997,75=20220919,119=918017.51,120=USD,78=1,79=LKLA ,80=918293,1908=1,1909=5493004U2OZSNMN2ML88852648401L0A0,1911=1,60=20220919-11:12:47,453=2,448=test#bc,447=C,452=11,448=BANK2,447=B,452=1,6977=1,6978=BANK2,6979=0.99965,
6980=0.00,6981=0.99965,6982=0.9997,6983=0.00,6984=0.9997,54=1,14=918293,38=918293,32=918293,7055=44536_0_0,10=124,
(tags 35=Execution report, 39=Filled, 150=Filled)
How do i get the above message(35=8 filled) in Onmessage/fromApp.
Is there any way/message that i can send to get all the executed trades till now?
something like:
8=FIX.4.4|9=158|35=8|34=3|49=AB|52=20220912-09:55:25.467|56=CD|6=0|11=44536|14=986604|17=00002|31=0|32=986604|37=00001|38=986604|39=2|54=1|55=EURUSD|58=44536|150=2|151=0|10=18
Thanks.
The reasons I know are:
Your lib might be ignoring PossDupFlag(43=Y) messages (IgnorePossDupResendRequests=Y configured if you are using QuickfixN - http://quickfixn.org/tutorial/configuration.html)
Your system is rejecting the messages that don't match against the DataDictionary used by the other counter party
Please check if your app is sending Reject messages (35=3) to the counter party immediately after receiving an ExecutionReport (35=8). If so, it will indicate that you might have some issues at your DataDictionary file. In this case your app will reject the messages and the ExecutionReport (35=8) will not be captured by your fromApp method.
My suggestion is:
check if you are sending 35=3 to the counter party. If it is true, check the 35=3 information, you will notice the reason the message was rejected
double check your data dictionary against the counter party's dictionary
double check if your session configuration file contains the entries below (considering quickfixJ)
ValidateFieldsOutOfOrder=N
ValidateFieldsHaveValues=N
ValidateUserDefinedFields=N
ValidateUnorderedGroupFields=N
AllowUnknownMsgFields=Y

how to Automate the process of Checking twitter profile have option of sending message or not

i want to check list of certain profile whether it profile has message function or not
so is it possible with selenium with the help python and requests
You can just use try-else to find that element and get value based on this:
try:
button = driver.find_element(...)
send_button = 1
else:
send_button = 0
You can expand this structure to a loop and store values in a nicer way like an array, column...
Be sure to carefully verify if the else statement triggers only when there is no button, e.g. by loading error.

I got an error while using selenium ,when I send values to the input field it starts sending in wrong order

when I'm sending values to the input field while using selenium, it sends values correctly up to 13 characters but when the value is greater than 13 characters it starts sending in something like reverse order.
My code is:
for character in Email:
actions = ActionChains(driver)
actions.move_to_element(Email)
actions.click()
actions.send_keys(character)
actions.perform()
time.sleep(random.uniform(0.2,0.5))
it prints in the following order :
waseem009#ya.mocooh
and my input is :
waseem009#yahoo.com
it sends correctly till waseem009#yah and after sending character "h", the cursor shifts between characters "a" and "h", and then the output is as above.
Website: https://www.easypost.com/signup
Not sure what is the exact issue, but as a workaround use pyperclip :
import pyperclip
pyperclip.copy('waseem009#yahoo.com')
and now it's in you clipboard, you can paste in send_keys()
actions.send_keys(pyperclip.paste())
My guess: move_to_element() moves the mouse to the center of the element. Then click() moves the input-position cursor to that screen position, which is sometimes in the middle of your already-entered text. It seems to me you'll need to redesign this.

How to find the last element in python selenium

I'm creating a web scraper for discord after logging in the bot should extract the last sent message in a discord channel and print it out. The last sent message however is dynamic. It always has a different path. It doesn't have an ID either. It only has a class name of embedFooterText-28V_Wb. As you know selenium returns the first element that has that class. In this case, it's the first message ever sent. How can I reverse it so it gets the last message sent? This is what I have written so far:
text = driver.find_element_by_class_name('embedFooterText-28V_Wb').get_attribute('innerHTML')
print(text)
This code returns the first message sent and I'd like to get the last message sent
you can find all of the elements the get last one with:
el1 = driver.find_elements_by_xpath("//*[contains(#class, 'embedFooterText-28V_Wb')]")[-1]
but better to get last one already with xpath functionality
Use (//*[contains(#class,'embedFooterText-28V_Wb')])[last()]
I used Java syntax however in Python it will be quite similar

How to verify that text is seen in the given xpath?

I'm using web driver to automate a test case. I'm trying to verify the text present in the page or not. I'm doing the following, but I don't know how to verify the textPresent is what I'm actually looking for.
textPresent = driver.find_element_by_xpath ("//span/p")
then when I did textPresent.text it's giving the text "An error occured processing Order" where I'm actually looking for "Successfuly added to processing" in the same xpath location. So in this situation, I want to fail the test case. How do i do that?
We should include a check point to verify the equality of actual text with expected :
expectedText = "Successfuly added to processing";
textPresent = driver.find_element_by_xpath ("//span/p");
if textPresent != expectedText
<Write fail condition here e.g. return "Fail" or raise Exception("Fail")>

Categories

Resources