我想将内容拖放到文本框中,然后通过我的下面代码将其拖到文本框中,但不要将其放在内容中。
WebElement from = driver.findElement(By.xpath("//*[@id='content']/table/tbody/tr[2]/th"));
WebElement to = driver.findElement(By.name("search"));
Action dragAndDrop = builder.clickAndHold(from).moveToElement(to).release(to).build();
dragAndDrop.perform();
答案 0 :(得分:0)
我建议您尝试以下解决方案:
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();
然后您可以使用Robot拖放元素