我正在尝试使用03012017表单将日期粘贴到日期表单中,代码为:
<input name="ctl00$ContentPlaceHolder2$response_def06a4c-a2c3-4120-a165-7ed24d106c6e" value="__/__/____" id="ctl00_ContentPlaceHolder2_response_def06a4c-a2c3-4120-a165-7ed24d106c6e" class="textboxcontrol" type="text">
我在eclipse上使用selenium并且我试图将excel表中的日期粘贴到不允许ctrl + v的表单中,因此使用sendkeys();我尝试但失败的方法,或右键单击并选择粘贴选项。
到目前为止我的代码是: 如果(集管并[a] .equals(&#34; datePartA&#34)){ String v_datePartA = formatter.formatCellValue(sheet.getRow(i).getCell(a));
// driver.findElement(By.id("ctl00_ContentPlaceHolder2_response_def06a4c-a2c3-4120-a165-7ed24d106c6e")).clear();
// driver.findElement(By.id("ctl00_ContentPlaceHolder2_response_def06a4c-a2c3-4120-a165-7ed24d106c6e")).click();
StringSelection stringSelection = new StringSelection(v_datePartA);
System.out.println("stringSelection is " + stringSelection);
Toolkit toolkit = Toolkit.getDefaultToolkit();
Clipboard clipboard = toolkit.getSystemClipboard();
clipboard.setContents(stringSelection, null);
System.out.println("Clipboard is " + stringSelection);
wait.until(ExpectedConditions.elementToBeClickable(By.id("ctl00_ContentPlaceHolder2_response_def06a4c-a2c3-4120-a165-7ed24d106c6e")));
WebElement Paste = driver.findElement(By.id("ctl00_ContentPlaceHolder2_response_def06a4c-a2c3-4120-a165-7ed24d106c6e"));
Actions builder = new Actions(driver);
//driver.findElement(By.id("ctl00_ContentPlaceHolder2_response_def06a4c-a2c3-4120-a165-7ed24d106c6e")).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("ctl00_ContentPlaceHolder2_response_def06a4c-a2c3-4120-a165-7ed24d106c6e")));
driver.findElement(By.id("ctl00_ContentPlaceHolder2_response_def06a4c-a2c3-4120-a165-7ed24d106c6e")).click();
builder.contextClick(Paste).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).perform();
如果有帮助,我也在使用firefox。
谢谢!