For Web elements, it is difficult to know whether an item exists, is visible, etc.
I achieved reliability using the DOM page location and width by comparing them to, in my example, a sliding menu position and width, as follows:
Public Function IsMenuVisible() As Boolean
Dim menuVisible As Boolean
'Get page position and width
Dim pageXPosition As Integer = repo.WebPage.Self.Element.ScreenLocation.X
Dim pageWidth As Integer = repo.WebPage.Self.Element.ScreenRectangle.Width
'Get configuration menu position and width
Dim menuXPosition As Integer = repo.WebPage.Menu.Self.Element.ScreenLocation.X
Dim menuWidth As Integer = repo.WebPage.Menu.Self.Element.ScreenRectangle.Width
'If menu top right location is >= web page size (out of screen)
If menuXPosition + menuWidth > pageXPosition + pageWidth Then
Report.Info(String.Format("Configuration menu is hidden (menuXPositon = {0}, pageXPosition = {1}, pageWidth = {2}, menuWidth = {3}).", menuXPosition, pageXPosition, pageWidth, menuWidth))
menuVisible = False
Else
Report.Info("Configuration menu is currently visible.")
menuVisible = True
End If
Return menuVisible
End Function
In my example, the menu is located on the right of the page. Please modify it according to your needs.
Then, do simple user code to loop a number of times to wait for the menu to appear as follows:
Public Sub WaitForMenuToAppear()
Dim retries As Integer = WaitForMenuToAppearRetries
While Not IsMenuVisible() AndAlso retries > 0
retries -= 1
Report.Info(String.Format("Waiting for configuration menu to be visible ({0}).", retries))
Delay.Duration(1000)
End While
If Not IsMenuVisible() Then
Throw New RanorexException(String.Format("Menu did not appear within '{0}' seconds.", WaitForMenuToAppearRetries))
Else
Report.Info("Menu is visible.")
End If
End Sub
I had to do this since the sliding is always visible. Using the highlight function of Ranorex Spy, the red rectangle is drawn outside the viewing area of the Web page.
I leave to you to complete the example.
Hope this helps…