Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right click and Drag and drop using Selenium webdriver

I am working on a qa automation project using Selenium webdriver.

I need to perform drag and drop on a telerik rad grid for reordering columns and then right click on the grid to save the changes made.

Is there any way i can achieve these using selenium webdriver ?

Thanks.

like image 326
WebDriver Avatar asked Dec 07 '11 04:12

WebDriver


People also ask

How do I drag and drop in Selenium WebDriver?

Find the required target element i.e. 'Drop Here' object in our sample. Now Drag and Drop 'Drag me to my target' object to 'Drop Here' object. Verify message displayed on 'Drop Here' to verify that source element is dropped at the target element. Close the browser to end the program.

Which is the correct way to perform right click using Selenium WebDriver?

Move to Element: contextClick() method first performs mouseMove to the middle of the element location. This function performs the right click at the middle of the web element. Build: build() method is used to generate a composite action containing all actions.

Can we do right click in Selenium?

Right click action in Selenium web driver can be done using Actions class. Right Click operation is also called Context Click in Selenium. Pre-defined method context click provided by Actions class is used to perform right click operation.

Can we automate drag and drop in Selenium?

Some web application, have a functionality to drag web elements and drop them on defined area or element. We can automate drag and drop of such elements using Selenium Webdriver.


1 Answers

For drag and drop you may try:

using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Firefox;    
using OpenQA.Selenium;

RemoteWebDriver driver =  new FirefoxDriver();
Actions action = new Actions(driver);
IWebElement sourceElement = FindElement(By.Id("id1"));
IWebElement targetElement = FindElement(By.Id("id2"));
IWebElement gridElement = FindElement(By.Id("grid"));
action.DragAndDrop(sourceElement, targetElement).Perform(); //drag&drop
Thread.Sleep(500); //if necessary
action.ContextClick(gridElement).Perform(); //right click

or you may use JavaScript for this.

like image 57
VMykyt Avatar answered Oct 11 '22 09:10

VMykyt