selenium使用robot对象操作键盘

本文介绍了如何利用selenium结合java的Toolkit类操作本地键盘,通过Toolkit.getDefaultToolkit().getSystemClipboard()获取系统剪切板,并展示了在网页元素定位及点击上的应用,以实现自动化测试中的键盘输入模拟。
摘要由CSDN通过智能技术生成
//通过Robot对象完成按键操作
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;

public class RobotTest {
	WebDriver driver;
	String url="https://www.baidu.com";
  @Test
  public void TestDemo() throws InterruptedException {
	  driver.get(url);
	  WebDriverWait wait = new WebDriverWait(driver,10);
	  //显式等待
	  wait.until(ExpectedConditions.presenceOfElementLocated(By.id("kw")));
	  driver.findElement(By.id("kw
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值