简体   繁体   English

如何在硒网格中执行拖放

[英]How to perform drag drop in selenium grid

I was installed selenium grid successfully but not able to perform drag drop operation in selenium grid. 我已经成功安装了硒网格,但是无法在硒网格中执行拖放操作。 if i run the code in testng it is working as expected, bu for grid it fail i learning selenium grid so unable to fix this issue, 如果我在testng中运行代码,它可以按预期运行,则bu for grid失败,我学习了硒网格,因此无法解决此问题,

jar: selenium-server-standalone-2.45.0.jar jar:selenium-server-standalone-2.45.0.jar

Selenium JAR: All jar from "selenium-2.45.0" (latest) Selenium JAR:“ selenium-2.45.0”中的所有jar(最新)

CODE: 码:

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) java.lang.ClassCastException:org.openqa.selenium.remote.RemoteWebDriver无法在qa.DragdropElements上的org.openqa.selenium.interactions.Actions。(Actions.java:41)上转换为org.openqa.selenium.interactions.HasInputDevices .DragdropElements1(DragdropElements.java:45)位于sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)at sun.reflect.NativeMethodAccessorImpl.invoke(未知源)

Try this and it might work 试试这个,它可能会起作用

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

Not sure why drag and drop isn't working for you. 不知道为什么拖放对您不起作用。 If you're running multi threads in your nodes try running with just tone thread. 如果您在节点中运行多线程,请尝试仅使用音频线程运行。 Also it's worth mentioning your node OS information. 另外,值得一提的是您的节点操作系统信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM