如何在selenium webdriver中自动绘制签名

时间:2014-10-27 09:27:43

标签: selenium webdriver

<div class="cnvsWrapper" style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; border: 0px none; padding: 0px; margin: 0px;">Draw your signature div>

步骤: 我需要选择工具提示,并需要在selenium webdriver中绘制签名(使用鼠标)。任何人都能帮助我吗?

6 个答案:

答案 0 :(得分:2)

下面的代码可以正常工作。关键是,在ClickAndHold()之后使用ContextClick()方法。根据您的需要放置坐标。

Actions builder = new Actions(getDriver());
WebElement canvasElement = getDriver().findElement(objMap.getLocator(Signature));
                
Action signature= builder.contextClick(canvasElement)                       
                       .clickAndHold()
                       .moveToElement(canvasElement,20,-50)
                       .moveByOffset(50, 50)
                       .moveByOffset(80,-50)
                       .moveByOffset(100,50)
                       .release(canvasElement)
                        .build();                       
                signature.perform();

答案 1 :(得分:1)

您可以使用Actions和moveByOffset交互“绘制”。但是,你不能(据我所知)绘制“复杂”的东西。

请参阅此代码示例:

      Actions builder = new Actions(driver);
      Action drawAction = builder.moveToElement(signatureWebElement, x, y)  
      //signatureWebElement is the element that holds the signature element you have in the DOM
                .clickAndHold()
                .moveByOffset(dest.x1, dest.y1)
                .moveByOffset(dest.x2, dest.y2)
                .release()
                .build();
            dragAction.perform();

答案 2 :(得分:0)

我解决了一个问题,就像绘制3个点将创建一个多边形,最后一次双击结束绘图过程,下面描述的代码对我来说很好

WebElement element = driver.findElement(By.xpath("xpath of canvas"));

    Actions builder = new Actions(driver);
    Action drawAction = builder.moveToElement(element,135,15) //start points x axis and y axis. 
              .click()
              .moveByOffset(200, 60) // 2nd points (x1,y1)
              .click()
              .moveByOffset(100, 70)// 3rd points (x2,y2)
              .doubleClick()
              .build();
    drawAction.perform();

答案 3 :(得分:0)

谢谢你的回答。

builder.moveToElement(AgreementSummaryPage.signatureTextArea,135,15)//起点x轴和y轴。                     .clickAndHold()。moveByOffset(165,15)。                             moveByOffset(185,15)

答案 4 :(得分:0)

使用appium 1.9.1,以下代码在Android api级别26 AVD设备上可以正常工作。

new TouchAction((MobileDriver)(driver))
    .press(new PointOption<>().withCoordinates(startX, startY))
    .moveTo(new PointOption<>().withCoordinates(endX, endY))
    .moveTo(new PointOption<>().withCoordinates(endX+50, endY+50))
    .release()
    .perform();

答案 5 :(得分:0)

Actions builder = new Actions(driver);
         Action signature= builder.moveToElement(element,100,50) 
//start points x axis and y axis. 
                 .clickAndHold()
                   .moveByOffset(150, 50) // 2nd point (x1,y1)
                   .click()
                   .build();
         signature.perform();

这将100%起作用,如果不起作用,请检查坐标是否在实际单击。您可以使用contextclick()代替clickandHold()或click()方法来检查它实际在何处被单击。 这正在网站https://www.docsketch.com/online-signature/draw/

中进行