Skip to content

Instantly share code, notes, and snippets.

@ShamaUgale
Last active September 10, 2020 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShamaUgale/8e5a355017397ad12fd45d0819304ea5 to your computer and use it in GitHub Desktop.
Save ShamaUgale/8e5a355017397ad12fd45d0819304ea5 to your computer and use it in GitHub Desktop.
This is an example to demonstarte the difference bewteen Actions class methods usages in selenium 3 and 4
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class DeprecatedExamples {
final static String PROJECT_PATH = System.getProperty("user.dir");
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", PROJECT_PATH+ "/src/main/resources/chromedriver");
ChromeDriver driver = new ChromeDriver();
/********************************************** Selenium 3 usage *************************************/
Actions act = new Actions(driver);
WebElement toDoList= driver.findElement(By.id("toDoListBtn"));
// click method - to click on a webElement
act.moveToElement(toDoList).click();
// double click - double click on a webElement
act.moveToElement(toDoList).doubleClick();
// Context click - Right click on a webElement
act.moveToElement(toDoList).contextClick();
//clickAndHold method - click and hold on a webElement without releasing
act.moveToElement(toDoList).clickAndHold();
// release -release the hold on a webElement
act.moveToElement(toDoList).release();
/********************************************** Selenium 4 usage *************************************/
Actions act1 = new Actions(driver);
WebElement toDoList1= driver.findElement(By.id("toDoListBtn"));
// click method - to click on a webElement
act1.click(toDoList);
//clickAndHold method - click and hold on a webElement without releasing
act1.clickAndHold(toDoList);
// Context click - Right click on a webElement
act1.contextClick(toDoList);
// double click - double click on a webElement
act1.doubleClick(toDoList);
// release -release the hold on a webElement
act1.release(toDoList);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment