Tuesday 8 June 2021

Multiple ways of clicking on Element with Selenium

We might be suprising sometimes while executing selenium script, though element is getting recognized, it is not clicking on the element. There could be various reasons for that 1. the element is rendering in the DOM which is not loaded but it is availalbe on the page 2. Element is available but it's href link made with # at the end, therefore it won't navigate any reference link But for the 1st reason we can use alternative options and make our selenium script working. Basically there 4 ways available to click on element with selenium. Following are the ways.


1. .Click

2. ((JavascriptExecutor) driver).executeScript("arguments[0].click();", yourelement);

3. yourelement.sendKeys(Keys.RETURN) or .sendKeys(Keys.ENTER)

4. Actions class: Actions actions = new Actions(driver); actions.click(signOnImage).perform();

8 comments: