ChromeDriver - stale element reference - selenium-chromedriver

I'm using ChromeDriver on Windows with AutoIt.
Work flow is like this: navigate to page, find element (input field), post text, submit is OK = so far, so good.
I a few seconds (also tried 30-40 seconds), repeat all operations, using exact same data (URL, text....)
Element is detected correctly both times, but submitting text second time fails with "stale element reference" error.
Find element AutoIt instruction:
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[#placeholder='Add comment']")
Result find element - first run:
__WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"76f56981-6062-40e5-a0d0-d1f9176141f7"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"76f56981-6062-40e5-a0d0-d1f9176141f7"}}
Send text and submit - first run:
URL=HTTP://127.0.0.1:9515/session/9fb1b3b3195ceaa07a4cfe3666a3f10e/element/76f56981-6062-40e5-a0d0-d1f9176141f7/value; $sData={"id":"76f56981-6062-40e5-a0d0-d1f9176141f7", "text":" XXXXX XXXXX"} __WD_Post: StatusCode=200; ResponseText={"value":null}...
Notice the same value is used, all OK: 76f56981-6062-40e5-a0d0-d1f9176141f7
Result find element - second run:
__WD_Post: URL=HTTP://127.0.0.1:9515/session/9fb1b3b3195ceaa07a4cfe3666a3f10e/element; $sData={"using":"xpath","value":"//*[#placeholder='Add comment']"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"e99cbe99-9b67-475d-b1aa-98028cb5d26e"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"e99cbe99-9b67-475d-b1aa-98028cb5d26e"}}
New element is found: e99cbe99-9b67-475d-b1aa-98028cb5d26e
Send text and submit - second run:
URL=HTTP://127.0.0.1:9515/session/9fb1b3b3195ceaa07a4cfe3666a3f10e/element/e99cbe99-9b67-475d-b1aa-98028cb5d26e/value; $sData={"id":"e99cbe99-9b67-475d-b1aa-98028cb5d26e", "text":" XXXX XXXX"} __WD_Post: StatusCode=404; ResponseText={"value":{"error":"stale element reference","message":"stale element reference: element is not attac... __WD_Post ==> No match: {"value":{"error":"stale element reference","message":"stale element reference: element is not attached to the page document\n (Session info: chrome=109.0.5414.75)","stacktrace":"Backtrace:\n\t(No symbol) [0x00596643]\n\t(No symbol) [0x0052BE21]\n\t(No symbol) [0x0042DA9D]\n\t(No symbol) [0x004309E4]\n\t(No symbol) [0x004308AD]\n\t(No symbol) [0x00430B30]\n\t(No symbol) [0x0045C474]\n\t(No symbol) [0x0045B7AB]\n\t(No symbol) [0x0047FD7C]\n\t(No symbol) [0x0045641F]\n\t(No symbol) [0x004800D4]\n\t(No symbol) [0x00496B09]\n\t(No symbol) [0x0047FB76]\n\t(No symbol) [0x004549C1]\n\t(No symbol) [0x00455E5D]\n\tGetHandleVerifier [0x0080A142+2497106]\n\tGetHandleVerifier [0x008385D3+2686691]\n\tGetHandleVerifier [0x0083BB9C+2700460]\n\tGetHandleVerifier [0x00643B10+635936]\n\t(No symbol) [0x00534A1F]\n\t(No symbol) [0x0053A418]\n\t(No symbol) [0x0053A505]\n\t(No symbol) [0x0054508B]\n\tBaseThreadInitThunk [0x772200F9+25]\n\tRtlGetAppContainerNamedObjectPath [0x77BA7BBE+286]\n\tRtlGetAppContainerNamedObjectPath [0x77BA7B8E+238]\n"}} _WD_ElementAction: {"value":{"error":"stale element reference","message":"stale element reference: element is not attac... _WD_ElementAction ==> No match: {"value":{"error":"stale element reference","message":"stale element reference: element is not attached to the page document\n (Session info: chrome=109.0.5414.75)","stacktrace":"Backtrace:\n\t(No symbol) [0x00596643]\n\t(No symbol) [0x0052BE21]\n\t(No symbol) [0x0042DA9D]\n\t(No symbol) [0x004309E4]\n\t(No symbol) [0x004308AD]\n\t(No symbol) [0x00430B30]\n\t(No symbol) [0x0045C474]\n\t(No symbol) [0x0045B7AB]\n\t(No symbol) [0x0047FD7C]\n\t(No symbol) [0x0045641F]\n\t(No symbol) [0x004800D4]\n\t(No symbol) [0x00496B09]\n\t(No symbol) [0x0047FB76]\n\t(No symbol) [0x004549C1]\n\t(No symbol) [0x00455E5D]\n\tGetHandleVerifier [0x0080A142+2497106]\n\tGetHandleVerifier [0x008385D3+2686691]\n\tGetHandleVerifier [0x0083BB9C+2700460]\n\tGetHandleVerifier [0x00643B10+635936]\n\t(No symbol) [0x00534A1F]\n\t(No symbol) [0x0053A418]\n\t(No symbol) [0x0053A505]\n\t(No symbol) [0x0054508B]\n\tBaseThreadInitThunk [0x772200F9+25]\n\tRtlGetAppContainerNamedObjectPath [0x77BA7BBE+286]\n\tRtlGetAppContainerNamedObjectPath [0x77BA7B8E+238]\n"}}
Even tough new element is found and used, I get error!
If I close the program completely and run it again, only first run works OK, same problem afterwards.
I have tried to use different variables.
I have tried to not reload page (Navigate 1 time, submit 1 = OK, submit 2 = fail).
I have tried to add pause / wait 30-40 seconds.

Workaround: delete session, create new session, navigate to new address.

Related

pyautogui write (or typewrite) does not work on samsung card payment page

I am trying to automate a purchase procedure.
after executing my codes to click on correct prompt buttons to get to card number input page, my code executes the following:
card_num = Image.open('C:\Python\RPA\card_num.png') #find card number input box
find_card_num = pyautogui.locateOnScreen(card_num, confidence = 0.65)
print(find_card_num)
pyautogui.moveTo(find_card_num[0] + (find_card_num[2]/2), find_card_num[1] +
(find_card_num[3]*0.6)) #move the mouse cursor to input box
time.sleep(.5)
pyautogui.click()
time.sleep(.5)
pyautogui.click() #click twice in an interval just in case the first one does not recognise it
time.sleep(5)
str_num = '4789531569875654' #any card number
pyautogui.typewrite(str_num, interval=0.25)' #type card number, I tried .write() as well
samsung_card_payment_page
my code correctly finds the location of the mouse point and clicks.
However, it does not type the card number. I believe the server system rejects or ignores the keyboard input that pyautogui sends, because the input box receives physical keyboard signals.
why does it happen and how do I make my code work?
Thank you

How to get canvas widget name from command?

I try to make popup menus that are in part defined by the widget that it was opened on. I can't seem to find a way to find which widget the menu is opened on. For example:
.f.canvas bind all <3> {
puts stderr "%W just gives me '.f.canvas'"
}
The widget name would be used for lookup in another table to change properties of the object related to the specific widget.
Try
.f.canvas bind all <3> {
puts stderr [%W find closest %x %y]
}
It should show the id of the item you clicked on.
When looking for some other stuff in the Tk documentation for canvas I came across the current tag:
The tag current is managed automatically by Tk; it applies to the
current item, which is the topmost item whose drawn area covers the
position of the mouse cursor (different item types interpret this in
varying ways; see the individual item type documentation for details).
If the mouse is not in the canvas widget or is not over an item, then
no item has the current tag.
Example of using it:
.f.canvas bind all <3> {
puts stderr "widget [%W find withtag current] says hello"
}

Trying to have + on positive and - on negative

This is the code I'm trying to make work...
"=IF (C11>0, "+",OTHERWISE "")
Trying to make it so that if the cell nect to it "C11" is over "0" It gets a "+" sign, otherwise if it's a negative number, Ex "-5", nothing will show up since the sign is negative.
This is my workaround to having to insert the apostrophe in front of the + everytime I want it to show up outside of a formula interaction.
Select every cell that you want to format (use ctrl-a to select all cells).
In the Format menu mouse-over Number, then mouse-over More Formats and select Custom Number Format. In the box presented to you type +0.00;-0.00.
Press Apply. This will format your numbers as desired.
See the Google Sheets documentation for more details.

Tab order with paper input and own element

I have made my own "date" input which consists of a paperinput, the pikaday date picker and a date validator (also my own). The reason for this is I have a requirement to both allow "vague" dates (if someone types 4 digits with a value between 1901 and 2050 that means any time in a specific year) and complex other rules so 2811 means 20th November current year (I am british so working with dd/mm/yy - but system I am replacing doesn't need the user to enter the / character).
I have a form with two paper-input fields followed by my date field. Tabbing moves nicely between them until I tab away from my special element, when for one tab nothing is selected and then the next tab the next field is selected.
I put some code on the blur event of my date elements paper input, and the did a var test = document.activeElement; in the event handler. The result of this is the body element from my page.
How do I make the tab order play nicely?
As I explained in the comment under the question, the pikaday date picker had received the tab on the blur, but was then immediately hidden. This left the tab with the body. I changed the various buttons on the picker to have tabindex="-1" added as the picker is created. This resolved the problem

background text for #Html.EditorFor

Is it possible to add some background text, ideally a prefix and suffix for #Html.EditorFor?
So if you I was rendering a page for someone to enter a company e-mail address or new AD name I'd like it so the ad box would have a persisted background prefix of
Domian\
And the cursor to start after the \
The e-mail to have persisted
#company.com
and the cursor to start before the #
The value doesn't have to be captured, just there and unchangeable.