【发布时间】:2017-05-02 19:48:00
【问题描述】:
我正在尝试下面的代码来测试 Selenium 3.0 中的拖放,发现代码不起作用,这意味着它没有显示任何错误,也没有提供预期的结果。
我在 selenium 2.53 中尝试过相同的代码,并且它正在工作。请有人检查我的代码,如果我遗漏了什么,请告诉我。
硒 3.0
浏览器:Mozilla 2.52
package dynamicXpath;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
public class refermeprobI {
public static void main(String[] args) throws InterruptedException{
System.setProperty("webdriver.gecko.driver", "D:\\Drivers\\geckodriver.exe");
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver(profile);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.get("https://the-internet.herokuapp.com/drag_and_drop");
Actions act = new Actions(driver);
WebElement src = driver.findElement(By.xpath("//*[@id='column-a']"));
WebElement dst = driver.findElement(By.xpath("//*[@id='column-b']"));
act.dragAndDrop(src, dst).build().perform();
System.out.println(driver.findElement(By.xpath("//*[@id='column-b']/header")).getText());
}
}
【问题讨论】:
-
我在您的代码中没有看到任何错误。但我仍然不确定您的 Mozilla Firefox 版本和 geckodriver 版本。使用 Selenium 3.x,拖放对我来说效果很好。
-
你用的是哪个版本的geckodriver?
-
我可以看到
setEnableNativeEvents(true)正在贬值。还能用吗?
标签: java selenium firefox selenium-webdriver