Why drag and drop is not working in Selenium Webdriver?

后端 未结 12 1659
借酒劲吻你
借酒劲吻你 2021-01-11 11:45

I am trying to drag an element into another element using Selenium WebDriver but it\'s not working. I tried all the solutions which I can find on internet but none of the so

12条回答
  •  清酒与你
    2021-01-11 12:06

    I would suggest you try the following solution:

    WebElement sourceelement  = driver.findElement(By.cssSelector("XXX"));
    Locatable element = (Locatable)sourceelement ;
    Point p= element.getCoordinates().inViewPort();
    int sourceX=p.getX();
    int sourceY=p.getY();
    
    WebElement destelement = driver.findElement(By.cssSelector("YYY"));
    Locatable elementTarget = (Locatable)destelement;
    Point Target= elementTarget.getCoordinates().inViewPort();
    int targetX=Target.getX();
    int targetY=Target.getY();
    

    You may then use Robot to drag and drop the element

提交回复
热议问题