[英]Selenium webdriver: double-click and copy-paste not working
我正在yahoo.com上尝试双击并复制粘贴方案,但是它不起作用。 想要复制文本“登录”并粘贴用户名
{ package com.yahoo.com;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;`
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class YahooTests {
WebDriver driver;
@Test
public void test01_InvokeBrowserApp(){
System.setProperty("webdriver.chrome.driver", "C:\\SeleniumDrivers\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
{ Actions act = new Actions(driver);
WebElement copy = driver.findElement(By.xpath(".//*[@id='mbr-login-greeting']"));
act.moveToElement(copy).doubleClick().sendKeys(Keys.CONTROL+"C").build().perform();
act.doubleClick(paste).sendKeys(Keys.CONTROL+"V");
WebElement paste = driver.findElement(By.xpath(".//*[@id='login-username']"));
}
试试这个希望问题会解决
act.moveToElement(By.xpath(".//*[@id='mbr-login-greeting']")).doubleClick().build().perform();
// catch here is double click on the text will by default select the text
// now apply copy command
driver.findElement(By.xpath(".//*[@id='mbr-login-greeting']")).sendKeys(Keys.chord(Keys.CONTROL,"c"));
// now apply the command to paste
driver.findElement (By.xpath(".//*[@id='login-username']").sendKeys(Keys.chord(Keys.CONTROL, "v"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.