I am attempting to paste from the clipboard using the Actions API.
It is as if the Control key is not being pressed. "V" is typed in the
input field.
I'm using Firefox 10.0.2
Running Selenium 2.21.0 on Windows.
Build info: version: '2.21.0', revision: '16552', time: '2012-04-11
19:09:00'
System info:
os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1',
java.version: '1.6.0_22'
I saw the same behavior with Selenium 2.19.0.
This test passes when I use the ChromeDriver.
This is my simple test scenario
import static org.junit.Assert.assertEquals;
import java.awt.Toolkit;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import org.junit.Test;
import
org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
public class SimpleTest
{
@Test
public void simpleTest() throws Exception
{
final WebDriver driver = new FirefoxDriver();
try
{
driver.get( "
http://localhost/test.html" );
driver.findElement( By.id( "test" ) );
final WebElement e = driver.findElement( By.id( "input" ) );
e.sendKeys( "typed" );
copyToClipboard( "pasted" );
final Actions builder = new Actions( driver );
builder.click( e ).keyDown( Keys.CONTROL ).sendKeys( "V" ).keyUp( Keys.CONTROL );
final Action paste = builder.build();
paste.perform();
assertEquals( "typedpasted", e.getAttribute( "value" ) );
}
finally
{
driver.quit();
}
}
public static void copyToClipboard( final String text )
{
final StringSelection stringSelection = new
StringSelection( text );
Toolkit.getDefaultToolkit().getSystemClipboard().setContents( stringSelection,
new ClipboardOwner()
{
@Override
public void lostOwnership( final java.awt.datatransfer.Clipboard
clipboard, final Transferable contents )
{
// do nothing
}
} );
}
}
And this is my html page:
<html>
<head></head>
<body>
<p>Hello World</p>
<input type="text" id="input"></input>
</body>
</html>
Am I doing something incorrectly, or does this look like a bug?
Thanks,
Brian