Forum Discussion

Shivani21's avatar
Shivani21
Occasional Contributor
8 months ago

If code for element exists results in failure

Hello, I am trying to do following code:

if Aliases.browser.Page("https://devtradewatch/tradewatch/Orders/viewOrdList.do",.FindElement("#colTD_0").Exists:
    Log.Message("Records are available, ntmOrders Search Passed")
  else:
    Log.Message("Records are not displayed, NTM Orders Failed")

Functionally it works correctly but whenever it does not find the element, it logs The object "Page("https://devtradewatch/tradewatch/Orders/viewOrdList.do")" does not exist" error in log.

How do I make it to not log it logs as all I am concerned with is using the following commands

  • Thank you for the suggestion. That would definitely help me for better representation of code and understanding as well.

    I could make it work by using WaitElement instead of FindElement.

    Thanks!

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I suggest you breakdown your lines of code into something simple that you can understand, e.g.

    var page = Aliases.browser.Page("https://devtradewatch/tradewatch/Orders/viewOrdList.do");
    var element = page.FindElement("#colTD_0");
    if (element.Exists) {
    	// Do something
    } else {
    	// Do something else
    }

    Then check where the error is occurring.

    If Aliases.browser.Page() is throwing an error, then are you using the correct browser? Does the URL actually exists in the browser? 

    • Shivani21's avatar
      Shivani21
      Occasional Contributor

      Thank you for the suggestion. That would definitely help me for better representation of code and understanding as well.

      I could make it work by using WaitElement instead of FindElement.

      Thanks!

      • rraghvani's avatar
        rraghvani
        Champion Level 3

        If Aliases.browser.Page() is throwing an error, then WaitElement() will not work either.