XCTWaiter().wait(for: [expectation], timeout: timeToWait) - Getting intermittently stall on main thread. How can I fix this

Before performing any action on element, I am waiting for element to appear. On xcode 11, I am getting this error stall on main thread randomly for some test cases. How can i fix this issue.