[英]How many ways can we implement Drag & Drop functionality using Selenium and Java
How many ways can we implement Drag & Drop functionality using Selenium and Java?使用 Selenium 和 Java 我们可以通过多少种方式实现拖放功能?
Code attempt:代码尝试:
Thread.sleep(3000);
WebElement FROM = driver.findElement(By.xpath("(//div[@class='item-container flex-container-horizontal'])[1]"));
Thread.sleep(3000);
WebElement to = driver.findElement(By.xpath("//div[text()='Product Quality?']"));
Thread.sleep(3000);
Actions act=new Actions(driver);
act.dragAndDrop(FROM, to).build().perform();
Drag and Drop functionality can be implemented in multiple ways as follows:拖放功能可以通过多种方式实现,如下所示:
Using dragAndDrop()
:使用
dragAndDrop()
:
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe"); WebDriver driver=new FirefoxDriver(); driver.get("http://jqueryui.com/droppable/"); driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@class='demo-frame']"))); WebElement from = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.id("draggable"))); WebElement to = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.id("droppable"))); new Actions(driver).dragAndDrop(from, to).build().perform();
Chaining clickAndHold()
and moveToElement()
:链接
clickAndHold()
和moveToElement()
:
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe"); WebDriver driver=new FirefoxDriver(); driver.get("http://jqueryui.com/droppable/"); driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@class='demo-frame']"))); WebElement drag = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.id("draggable"))); WebElement drop = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.id("droppable"))); new Actions(driver).clickAndHold(from).moveToElement(to).release(from).build().perform();
Video demonstration:视频演示:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.