Amazing piece that I learnt today; Composite actions. Its a concept in which you carry several action commands within one line of Selenium code.
For an example, un the below syntax I perform these actions;
move to the search bar, press it, hold down shift key and enter a text and then double-clicking on the text.
So how is it done.
We have used the "Actions" class within org.openqa.selenium.interactions.Actions.
Actions a = new Actions(driver);
WebElement caps = driver.findElement(By.xpath("//input[@id=\"twotabsearchtextbox\"]"));
a.moveToElement(caps).clickAndHold().keyDown(Keys.SHIFT).sendKeys("iphoneX").doubleClick().build().perform()
It supports many actions such as below
clickAndHold().
keyDown(Keys).
sendKeys("iphoneX")
doubleClick()
Once you have selected the action classes required for your test, in Selenium Java you need to end the command with .build().perform();
Complete code is as below;