• Selenium Video Tutorials

Selenium WebDriver - 笔事件



Selenium Webdriver 可用于执行类似于笔触的指针输入,以与页面上的 Web 元素进行通信。这使用Actions 类执行。笔事件仅在 Chromium 浏览器中可用。

什么是笔操作?

笔类似于指针输入,具有与鼠标相似的特性。它还可以具有与触控笔不同的事件属性。鼠标有五个按钮,而笔只有三个按钮:0 表示触摸接触(类似于左键单击)、2 表示笔筒按钮(类似于右键单击)和 5 表示橡皮擦按钮(驱动程序目前尚不支持)。

执行笔事件的语法

WebElement a = driver.findElement(By.xpath("xpath of pointer area")); new Actions(driver) .setActivePointer(PointerInput.Kind.PEN, "default pen") .moveToElement(a) .clickAndHold() .moveByOffset(5, 5) .release() .perform();

执行指针事件属性的语法

WebElement a = driver.findElement(By.xpath("xpath of pointer area")); PointerInput p = new PointerInput(PointerInput.Kind.PEN, "default pen"); PointerInput.PointerEventProperties eventProperties = PointerInput.eventProperties() .setTiltX(-82) .setTiltY(10) .setTwist(98); PointerInput.Origin o = PointerInput.Origin.fromElement(a); Sequence act = new Sequence(p, 0) .addAction(p.createPointerMove(Duration.ZERO, origin, 0, 5)) .addAction(p.createPointerDown(0)) .addAction(p.createPointerMove(Duration.ZERO, origin, 2, 7, eventProperties)) .addAction(p.createPointerUp(0)); ((RemoteWebDriver) driver).perform(Collections.singletonList(act));

因此,在本教程中,我们讨论了使用 Selenium Webdriver 的笔事件。

广告