gpt4 book ai didi

java - 如何在 Selenium 网格中执行拖放

转载 作者:太空宇宙 更新时间:2023-11-04 14:03:35 24 4
gpt4 key购买 nike

我已成功安装selenium grid,但无法在selenium grid中执行拖放操作。如果我在 testng 中运行代码,它会按预期工作,但对于网格来说,它失败了,我学习 Selenium 网格,因此无法解决此问题,

jar:selenium-server-standalone-2.45.0.jar

Selenium JAR:来自“selenium-2.45.0”(最新)的所有 jar

代码:

public class DragdropElements {WebDriver driver;
String nodeURL;
@BeforeTest
public void draganddrop() throws MalformedURLException
{
// driver = new FirefoxDriver();
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger");
nodeURL = "http://localhost:4444/wd/hub";
DesiredCapabilities cap = new DesiredCapabilities();
cap.setBrowserName("firefox");
/// cap.setVersion("31.0");
//cap.setPlatform(Platform.VISTA);
driver = new RemoteWebDriver(new URL(nodeURL),cap);
driver.get("http://only-testing-blog.blogspot.in/2014/09/drag-and-drop.html");
}

@Test
public void DragdropElements1() throws InterruptedException
{
WebElement DragFrom = driver.findElement(By.xpath("//*[@id='dragdiv']"));
WebElement DragTo = driver.findElement(By.xpath("//*[@id='dropdiv']"));

Actions builder = new Actions(driver);
Action dragAndDrop3 = builder.dragAndDrop(DragFrom, DragTo).build();
dragAndDrop3.perform();

String Texttocompare = driver.findElement(By.xpath("//*[@id='Blog1']/div[1]/div/div/div/div[1]/h3")).getText();
System.out.println(""+Texttocompare);
Assert.assertEquals(Texttocompare, "Drag and Drop");
}
}

异常(exception):

java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver cannot be cast to org.openqa.selenium.interactions.HasInputDevices at org.openqa.selenium.interactions.Actions.(Actions.java:41) at qa.DragdropElements.DragdropElements1(DragdropElements.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

最佳答案

尝试一下,它可能会起作用

Actions actionsBuilder = new Actions(driver);
builder.keyDown(Keys.CONTROL)
.click(elementName)
.keyUp(Keys.CONTROL);
Action action = actionsBuilder.build();
action.perform();

不确定为什么拖放功能不适合您。如果您在节点中运行多线程,请尝试仅使用音频线程运行。另外值得一提的是您的节点操作系统信息。

关于java - 如何在 Selenium 网格中执行拖放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29079436/

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