Forum Discussion
This is because the type of error raised is not a code exception but an operation exception with the "click" action. These are not caught by try/catch.
Suggestion. In your code for doing the object click, before the click, do a check for VisibleOnScreen. If VisibleOnScreen is false, then call obj.scrollIntoView(true). This will scroll the web page to the component before the click.
hi tristaanogre,
Thank you for your reply.
your suggestion work well for me
below is the code i use, which is actually from AlexKaras
if (!obj.VisibleOnScreen) { obj.scrollIntoView(true); if (!obj.VisibleOnScreen) { obj.scrollIntoView(false); } } obj.Click();
I have the same issue but in a Windows app rather thana web page
Aliases.MyApp.HwndSource_MainWindow.MainWindow.m_NodeControl.ExpandItem(("|[2]"));
Aliases.MyApp.HwndSource_MainWindow.MainWindow.m_NodeControl.Refresh();
Aliases.MyApp.HwndSource_MainWindow.MainWindow.m_NodeControl.DblClickItem("|[2]|[0]");The third line craters if the tree view is scroll off the screen so node 2 is not visible
I can't call is visible on the NodeControl as it always is
How do I ensure node 2 is visible ?
Scratch the above - I just call collapse on each branch and it comes into view
- tristaanogre7 years agoEsteemed Contributor
Alternatively, you could check the VisibleOnScreen property. If it is false, execute a page down or some other scroll event to bring the component to be visible on screen.