尝试执行硒的拖放操作,但这只是拖动元素而没有将其拖放到目标上

时间:2019-10-13 11:14:25

标签: selenium-chromedriver

试图执行硒的拖放操作,但这只是拖动元素而没有将其拖放到目标上

我尝试使用以下代码。

WebElement ELE1=driver.findElement(By.xpath("//li[@id='Text']//a[@class='nav-link']"));
    WebElement ELE2=driver.findElement(By.xpath("//div[@id='sectionPage_773page1']"));
    Actions action= new Actions(driver);
    action.clickAndHold(ELE1).perform();
    Thread.sleep(1000);
    action.moveToElement(ELE2).perform();
    Thread.sleep(1000);
    action.release(ELE2).build().perform();
    Thread.sleep(1000);

WebElement des = driver.findElement(By.xpath("//div[@id='sectionPage_773page1']"));
    WebElement src= driver.findElement(By.xpath("//li[@id='Text']//a[@class='nav-link']"));
    Boolean js = false;
    Boolean js1 = false;
    js=des.isDisplayed();
    js1 = src.isDisplayed();
    System.out.println("Des display"+js);
    System.out.println("Sec display"+js1);
    act.dragAndDrop(src, des).build().perform();
    act.clickAndHold(src);
    act.moveToElement(des);
    act.release(des);
    act.build().perform();

    Point co1= src.getLocation();
    Point co2= des.getLocation();
    Robot rb = new Robot();
    rb.setAutoDelay(15);
    rb.keyPress(KeyEvent.VK_F11);
    act.dragAndDropBy(src, co2.getX(),co2.getY());

    Point coordinate1 = src.getLocation();
    Point coordinate2 = des.getLocation();
    Robot rbt = new Robot();
    rbt.mouseMove(coordinate1.getX(), coordinate2.getY());
    rbt.setAutoDelay(15);
    rbt.mousePress(InputEvent.BUTTON1_MASK);
    rbt.mouseMove(coordinate2.getX(),coordinate2.getY());
    rbt.setAutoDelay(15);
    rbt.mouseRelease(InputEvent.BUTTON1_MASK);

WebElement source = driver.findElement(By.cssSelector("div.wrapper:nth-child(2) div.fixed-s0idebar.col-lg-2.offset-lg-10.p-0.right-zero div.sidebar-editor-right div.col-lg-12.p-0:nth-child(1) div.tool-box ul.nav.justify-content-center li.nav-item:nth-child(5) a.nav-link > img:nth-child(1)"));
    Actions builder = new Actions (driver);
    builder.dragAndDropBy(source, 282, 100).click().build().perform();

上面所有代码都没有给我任何错误,但是当我尝试上一个代码时,它给了我将目标移出绑定异常的可能性

0 个答案:

没有答案