Is there any way to perform a copy and paste using Selenium 2 and the Python bindings?
I\'ve highlighted the element I want to copy and then I perform the following
If you want to copy a cell text from the table and paste in search box,
Actions Class : For handling keyboard and mouse events selenium provided Actions Class
///
/// This Function is used to double click and select a cell text , then its used ctrl+c
/// then click on search box then ctrl+v also verify
///
///
public void SelectAndCopyPasteCellText(string text)
{
var cellText = driver.FindElement(By.Id("CellTextID"));
if (cellText!= null)
{
Actions action = new Actions(driver);
action.MoveToElement(cellText).DoubleClick().Perform(); // used for Double click and select the text
action = new Actions(driver);
action.KeyDown(Keys.Control);
action.SendKeys("c");
action.KeyUp(Keys.Control);
action.Build().Perform(); // copy is performed
var searchBox = driver.FindElement(By.Id("SearchBoxID"));
searchBox.Click(); // clicked on search box
action = new Actions(driver);
action.KeyDown(Keys.Control);
action.SendKeys("v");
action.KeyUp(Keys.Control);
action.Build().Perform(); // paste is performed
var value = searchBox.GetAttribute("value"); // fetch the value search box
Assert.AreEqual(text, value, "Selection and copy paste is not working");
}
}
KeyDown(): This method simulates a keyboard action when a specific keyboard key needs to press.
KeyUp(): The keyboard key which presses using the KeyDown() method, doesn’t get released automatically, so keyUp() method is used to release the key explicitly.
SendKeys(): This method sends a series of keystrokes to a given web element.