Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.AccessViolationException: Attempted to read or write protected memory on scrolling #218

Open
SamGeens opened this issue Nov 14, 2024 · 6 comments

Comments

@SamGeens
Copy link

SamGeens commented Nov 14, 2024

Background:
We are trying to automate a testcase via robot framework via FlaUI library. We have a custom made GUI to control. Before, we were using TestStackWhite and with that library we were able to scroll up/down in the list and find the "element"/"row" we wanted to interact with.

Issue:
After solving the previous issue. We ran into a new issue. The following error is thrown at random times during our scroll process:

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AccessViolationException: Attempted to read or write protected memory. This is of
ten an indication that other memory is corrupt.
   at Interop.UIAutomationClient.IUIAutomationTreeWalker.GetNextSiblingElement(IUIAutomationElement element)
   at FlaUI.UIA3.UIA3TreeWalker.GetNextSibling(AutomationElement element)
   at FlaUI.Core.AutomationElementXPathNavigator.MoveToNext()
   at MS.Internal.Xml.XPath.XPathDescendantIterator.MoveNext()
   at MS.Internal.Xml.XPath.DescendantQuery.Advance()
   at MS.Internal.Xml.XPath.FilterQuery.Advance()
   at MS.Internal.Xml.XPath.CacheChildrenQuery.GetNextInput()
   at MS.Internal.Xml.XPath.CacheChildrenQuery.DecideNextNode()
   at MS.Internal.Xml.XPath.CacheChildrenQuery.Advance()
   at MS.Internal.Xml.XPath.FilterQuery.Advance()
   at MS.Internal.Xml.XPath.CacheChildrenQuery.GetNextInput()
   at MS.Internal.Xml.XPath.CacheChildrenQuery.Advance()
   at MS.Internal.Xml.XPath.FilterQuery.Advance()
   at MS.Internal.Xml.XPath.CacheChildrenQuery.GetNextInput()
   at MS.Internal.Xml.XPath.CacheChildrenQuery.Advance()
   at MS.Internal.Xml.XPath.FilterQuery.Advance()
   at MS.Internal.Xml.XPath.XPathSelectionIterator.MoveNext()
   at System.Xml.XPath.XPathNavigator.SelectSingleNode(XPathExpression expression)
   at System.Xml.XPath.XPathNavigator.SelectSingleNode(String xpath)
   at FlaUI.Core.AutomationElements.AutomationElement.FindFirstByXPath(String xPath)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Python.Runtime.MethodBinder.Invoke(BorrowedReference inst, BorrowedReference args, BorrowedReference kw, MethodBase info, MethodBase[] methodinfo)
   at Python.Runtime.MethodObject.Invoke(BorrowedReference target, BorrowedReference args, BorrowedReference kw, MethodBase info)
   at Python.Runtime.MethodBinding.tp_call(BorrowedReference ob, BorrowedReference args, BorrowedReference kw)

The code we are executing is the following:

${total_rows_in_list}  UUT.get grid rows Count  ${item_list}

log to console  Checking the item list to find..

# Less attempts needed than rows in list. Each scroll is 3 list items and we scroll 5 times at once.

# Added 10 more scrolls for safe margin.
${scroll_attempts} =   Evaluate    ${total_rows_in_list} / 15 + 10

FOR    ${i}    IN RANGE    ${total_rows_in_list}
    ${item_found}  Set variable  False
    UUT.Scroll down   ${item_list}  1
    UUT.Scroll down   ${item_list}  1
    UUT.Scroll down   ${item_list}  1
    UUT.Scroll down   ${item_list}  1
    UUT.Scroll down   ${item_list}  1

    Suspend For  2 s
    # Check if item is in current list view
    ${needed_item_is_present}  ${msg}  run keyword and ignore error  UUT.Is element offscreen  ${demo_item}

    IF  '${needed_item_is_present}' == 'PASS'
        log to console  Item NR has been found!
        # Scroll down one more time because it might be not "visible"
        UUT.Scroll down   ${item_list}  1
        Sleep  2s
        log to console  Clicking on the item...
        UUT.Click  ${demo_item}

        Set variable  ${item_found}  True
        Exit For Loop
    END
END

Do you have any idea/indication on how to prevent the memory issue. Our implementation is currently unstable because of this.

@Nepitwin
Copy link
Member

Hi @SamGeens ,

which kind of element are you trying to scroll down and language?

Maybe i can reproduce this part afterwards to identify why an Access Violation will be thrown.

@SamGeens
Copy link
Author

SamGeens commented Nov 15, 2024

Hi @Nepitwin,

The application without sensitive data looks like this:
image

The scroll list is a data grid:
image

@noubar
Copy link
Contributor

noubar commented Nov 15, 2024

@SamGeens

Please try the following and update us with the results, If the error is the same or you are getting another error or it fixes it

UUT.Scroll down ${item_list} 1 if_focus=${Flase}

What you have not yet answered is this a c# project with WPF or is it windows Form or something else?

@SamGeens
Copy link
Author

Hi @noubar,

I tried UUT.Scroll down ${item_list} 1 if_focus=${Flase} but the same error occurs.

This is a .NET Framework 4.8 WPF project

@SamGeens
Copy link
Author

The problem is mostlikely with checking a list item that is not yet in the current window:

${needed_item_is_present} ${msg} run keyword and ignore error UUT.Is element offscreen ${demo_item}

@noubar
Copy link
Contributor

noubar commented Nov 25, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants