Search This Blog

Breaking

Thursday, 28 October 2021

[Fix] Selenium click is not working in Jenkin while working fine in Local

 If the click() in your selenium UI script is failing in Jenkin machine, but in local, it is working fine, then you can use below tricks:

1. Replace selenium click() to JavaScript Executor click()

JavascriptExecutor javascriptExecutor =  (JavascriptExecutor) driver;

javascriptExecutor.executeScript("arguments[0].click();", element);





2. Scroll till that element first, and then perform click.

JavascriptExecutor javascriptExecutor =  (JavascriptExecutor) driver;

javascriptExecutor.executeScript("arguments[0].scrollIntoView();", element);

3. Use double click

element.doubleClick()

4. Use isDisplayed(), isClickable(), waitForPageToLoad() method. It will buy some time before clicking on that element.

5. Use Hardcode for debugging purpose. Check that, is it failing because element is not visible.

6. Try to do getText() for that element. If the locator is working, it should return text for that element also if it's present.

7. Try to find out window size of that jenkin machine where your code is running. There are chances, that the browser size is different in your local to Jenkin machine.

You can use below code for that:

Dimension dimension = driver.manage().window().getSize();

LOGGER.info("dimension is " + dimension);

Later set the size.

driver.manage().window().setSize(new Dimension(1280, 768));

8. Use fullScreen, maxsize for browser.

driver.Manage().Window.Maximize();



No comments:

Post a Comment