Selenium webdriver click vs action.click whats the difference? Selenium webdriver click vs action.click whats the difference? selenium selenium

Selenium webdriver click vs action.click whats the difference?


I am not sure about your specific case, but there are several differences between WebElement click method and Actions click method. Actions' click is a lot dumber, it pretty much just sends the click event to the element (location) that you pass in. It does not care about the element, it just does the click and moves forward whereas webelement click is a blocking call (not always, check the references) and it also has preconditions like the WebElement to be clicked must be visible. Also, webElements' click is a void method, actions click returns reference to the Actions you are using. For more information check here and here.


edit.Looking at the markup you posted, and it can be totally wrong as I am not a boss on bootstrap CSS, the modal hide fade in and especially the fade in part there looks suspicious. Are you sure that when you send the webelement.click(), your element is in clickable state? What happens? Nothing? Then again, if the actions click is reliably working, why not just go with it, I mean, if something works, why fix it?


Just testing similar scenario.

First with Actions click:

actions.moveToElement(driver.findElement(By.xpath("//*[@id='relevantJobsAndCareerUpdates_1']"))).click().perform()

And second one with WebElement click:

driver.findElement(By.xpath("//*[@id='relevantJobsAndCareerUpdates_1']"))).click()

The second one does not work. It gives the error message:

Root cause: org.openqa.selenium.WebDriverException: unknown error: Element <input data-val-required="Information required." id="relevantJobsAndCareerUpdates_1" name="OptiInEmailJobsAndCarrerRelated" type="radio" value="1"> is not clickable at point (307, 24). Other element would receive the click: <label for="relevantJobsAndCareerUpdates_1" class="control-label">...</label>

This is the similar problem as previous. Using Actions solve this problem.