Skip to content

Tips and Tricks

peterrexj edited this page Sep 10, 2019 · 1 revision

Tips and Tricks in automation (Selenium Essentials)

Declaring controls

Use expression while declaring controls. For example, with the below line using (=>), whenever you access the control, every time it tries to retry and find element without storing into a field. This will help to avoid the StaleException and always make sure the element is available in the page.

private WebControl _panelContainer => new WebControl(_driver, By.CssSelector("div.panelContainer"));

Wait and Click

Use WaitAndClick(int timeToWaitInSeconds), when you have elements visible but due to some animation on the responsive page, fails to make the click operation. Use wait and click and pass 1 or 2 seconds for wait, to complete the animation and proceed with the click operation.

Clone this wiki locally