gpt4 book ai didi

java - 仅此网站无法拖放 Selenium

转载 作者:行者123 更新时间:2023-12-01 16:28:17 25 4
gpt4 key购买 nike

WebDriver driver = new ChromeDriver(); //Launch the chrome browser
driver.get("https://www.seleniumeasy.com/test/drag-and-drop-demo.html");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@id=\"todrag\"]/span[2]"));
WebElement from = driver.findElement(By.xpath("//*[@id=\"todrag\"]/span[2]"));
WebElement to = driver.findElement(By.xpath("//*[@id='mydropzone']"));
Actions builder = new Actions(driver);
builder.dragAndDrop(from, to).perform();

最佳答案

我把它放在Junit测试中。对我来说效果很好。

但我注意到您没有设置属性来使用本地 chromedriver。

你有chromedriver吗?下载了吗?


private WebDriver driver;

@Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver",
//"C:/path/to/your/chromedriver.exe"
"/path/to/your/chromedriver"); // Might be this.
driver= new ChromeDriver();
}

@After
public void tearDown() throws Exception {
driver.quit();
}

@Test
public void testDragNDrop() {
driver.get("https://www.seleniumeasy.com/test/drag-and-drop-demo.html");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@id=\"todrag\"]/span[2]"));
WebElement from = driver.findElement(By.xpath("//*[@id=\"todrag\"]/span[2]"));
WebElement to = driver.findElement(By.xpath("//*[@id='mydropzone']"));
Actions builder = new Actions(driver);
builder.dragAndDrop(from, to).perform();
}

关于java - 仅此网站无法拖放 Selenium ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62118129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com