Actions in selenium webdriver
In this article we are going to see how many type of action can be perform in selenium web driver. I am using C#(VS 2010). We will see different methods to perform action.
Preliminary ideas is , every new action needs to build and then it will be ready to perform. That means, in most of the cases, we will use .Build() and then .perform() after initiation new action.
Actions Class is responsible for every action performed in browser. It is under namespace OpenQA.Selenium.Interactions.
The default constructor :
Actions(driver); //driver is the objcet of any browser driver[driver = new FirefoxDriver();]
Actions that can be performed by Action Class :
-To Build a sequence of actions and that returns IAction
new Actions(driver).Build();
-To Perform the currently built action and no return
new Actions(driver).Perform();
-To Perform specific action on the browser and no return
new Actions(driver).Build().Perform();//better to specify by finding element
-To Click mouse at the last known mouse coordinates and that returns Actions
new Actions(driver).Click();
-To Click the mouse on the specified element and that returns Actions
new Actions(driver).Click(draggable);
-To Click and hold the mouse button at the last known mouse coordinates and that returns Actions
new Actions(driver).ClickAndHold();
-To Click and hold the mouse button down on the specified element and that returns Actions
new Actions(driver).ClickAndHold(draggable);
-To Right-click the mouse at the last known mouse coordinates and that returns Actions.
new Actions(driver).ContextClick();
-To Right-click the mouse on the specified element and that returns Actions.
new Actions(driver).ContextClick(draggable);
-To Double-click the mouse at the last known mouse coordinates and that returns Actions.
new Actions(driver).DoubleClick();
-To Double-click the mouse on the specified element and that returns Actions.
new Actions(driver).DoubleClick(draggable);
-To drag-and-drop from one element to another and that returns Actions.
new Actions(driver).DragAndDrop(draggable, droppable);
-To drag-and-drop on one element to a specified offset and that returns Actions.
new Actions(driver).DragAndDropToOffset(draggable, 25, 35);
-To Send a modifier key down message to the browser and that returns Actions.
new Actions(driver).KeyDown(Keys.Alt);//key parameter as string
-To Send a modifier key down message to the specified element in the browser and that returns Actions.
new Actions(driver).KeyDown(draggable, Keys.Alt);//key parameter as string
-To Send a modifier key up message to the browser and that returns Actions.
new Actions(driver).KeyUp(Keys.Alt);//key parameter as string
-To Send a modifier up down message to the specified element in the browser and that returns Actions.
new Actions(driver).KeyUp(draggable, Keys.Alt);//key parameter as string
-To Move the mouse to the specified offset of the last known mouse coordinates and that returns Actions.
new Actions(driver).MoveByOffset(25, 35);//(Xoffset, Yoffset)
-To Move the mouse to the specified element and that returns Actions.
new Actions(driver).MoveToElement(draggable);
-To Move the mouse to the specified offset of the top-left corner of the specified element and that returns Actions.
new Actions(driver).MoveToElement(draggable, 25, 35);//(Xoffset, Yoffset)
-To Release the mouse button at the last known mouse coordinates and that returns Actions.
new Actions(driver).Release();
-To Release the mouse button on the specified element and that returns Actions.
new Actions(driver).Release(draggable);
-To Send a sequence of keystrokes to the browser and that returns Actions.
new Actions(driver).SendKeys(Keys.Alt);//key parameter as string
-To Send a sequence of keystrokes to the specified element in the browser and that returns Actions.
new Actions(driver).SendKeys(draggable,Keys.Alt);//key parameter as string
Note : Here draggable and droppable are two web element(IWebElement type). All action I used with new(to perform separately). Returns Actions means, the function return Action type object. When necessary, we can use this.
...Thanks...:) I will try to use those in my examples in future posts.
Preliminary ideas is , every new action needs to build and then it will be ready to perform. That means, in most of the cases, we will use .Build() and then .perform() after initiation new action.
Actions Class is responsible for every action performed in browser. It is under namespace OpenQA.Selenium.Interactions.
The default constructor :
Actions(driver); //driver is the objcet of any browser driver[driver = new FirefoxDriver();]
Actions that can be performed by Action Class :
-To Build a sequence of actions and that returns IAction
new Actions(driver).Build();
-To Perform the currently built action and no return
new Actions(driver).Perform();
-To Perform specific action on the browser and no return
new Actions(driver).Build().Perform();//better to specify by finding element
-To Click mouse at the last known mouse coordinates and that returns Actions
new Actions(driver).Click();
-To Click the mouse on the specified element and that returns Actions
new Actions(driver).Click(draggable);
-To Click and hold the mouse button at the last known mouse coordinates and that returns Actions
new Actions(driver).ClickAndHold();
-To Click and hold the mouse button down on the specified element and that returns Actions
new Actions(driver).ClickAndHold(draggable);
-To Right-click the mouse at the last known mouse coordinates and that returns Actions.
new Actions(driver).ContextClick();
-To Right-click the mouse on the specified element and that returns Actions.
new Actions(driver).ContextClick(draggable);
-To Double-click the mouse at the last known mouse coordinates and that returns Actions.
new Actions(driver).DoubleClick();
-To Double-click the mouse on the specified element and that returns Actions.
new Actions(driver).DoubleClick(draggable);
-To drag-and-drop from one element to another and that returns Actions.
new Actions(driver).DragAndDrop(draggable, droppable);
-To drag-and-drop on one element to a specified offset and that returns Actions.
new Actions(driver).DragAndDropToOffset(draggable, 25, 35);
-To Send a modifier key down message to the browser and that returns Actions.
new Actions(driver).KeyDown(Keys.Alt);//key parameter as string
-To Send a modifier key down message to the specified element in the browser and that returns Actions.
new Actions(driver).KeyDown(draggable, Keys.Alt);//key parameter as string
-To Send a modifier key up message to the browser and that returns Actions.
new Actions(driver).KeyUp(Keys.Alt);//key parameter as string
-To Send a modifier up down message to the specified element in the browser and that returns Actions.
new Actions(driver).KeyUp(draggable, Keys.Alt);//key parameter as string
-To Move the mouse to the specified offset of the last known mouse coordinates and that returns Actions.
new Actions(driver).MoveByOffset(25, 35);//(Xoffset, Yoffset)
-To Move the mouse to the specified element and that returns Actions.
new Actions(driver).MoveToElement(draggable);
-To Move the mouse to the specified offset of the top-left corner of the specified element and that returns Actions.
new Actions(driver).MoveToElement(draggable, 25, 35);//(Xoffset, Yoffset)
-To Release the mouse button at the last known mouse coordinates and that returns Actions.
new Actions(driver).Release();
-To Release the mouse button on the specified element and that returns Actions.
new Actions(driver).Release(draggable);
-To Send a sequence of keystrokes to the browser and that returns Actions.
new Actions(driver).SendKeys(Keys.Alt);//key parameter as string
-To Send a sequence of keystrokes to the specified element in the browser and that returns Actions.
new Actions(driver).SendKeys(draggable,Keys.Alt);//key parameter as string
Note : Here draggable and droppable are two web element(IWebElement type). All action I used with new(to perform separately). Returns Actions means, the function return Action type object. When necessary, we can use this.
...Thanks...:) I will try to use those in my examples in future posts.