5

I'm pretty new to selenium and when i'm running code below for Selenium WebDriver in Eclipse (Java), i'm getting this exception:

"Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: mouseMoveTo"

Here is the code:

    WebDriver driver = new FirefoxDriver();
    driver.get("http://newtours.demoaut.com/");
    WebElement myElement = driver.findElement(By.cssSelector("input[name=userName]"));

    Actions myAction = new Actions(driver);
    myAction.moveToElement(myElement)
        .click()
        .keyDown(myElement, keys.SHIFT)
        .sendKeys(myElement, "test")
        .keysUp(myElement, keys.SHIFT)
        .(myElement)
        .contextClick()
        .build()
        .perform();

What causes this error?

Thanks and regards.

rabejens
  • 7,594
  • 11
  • 56
  • 104
Rishabh Jain
  • 137
  • 3
  • 10

3 Answers3

5

There is a known issue with the new Version of the FirefoxDriver namely the GeckoDriver, which doesn´t support the Action class see:

Selenium web driver moveToElement (Actions) throwing error with marionette driver?

https://github.com/SeleniumHQ/selenium/issues/3348

Without more info I´d assume this is also your problem. If you need to test with FF then use an older version or Chrome with the ChromeDriver

Community
  • 1
  • 1
3

Try this below xpath:

Explanation: Your input tag, parent tag is table so start xpath with table tag and then move ahead with using following keyword to input tag.

driver.findElement(By.xpath("//table/../following::input[@name='userName']")).sendKeys("USERNAME");
Jainish Kapadia
  • 2,603
  • 5
  • 18
  • 29
  • 1
    Hi, My code is working till actions class initialization. But thanx for reply – Rishabh Jain Mar 01 '17 at 12:33
  • As Enrique pointed out i think problem must be in GreckoDriver .. – Rishabh Jain Mar 01 '17 at 12:35
  • @Rishabh Can you explain why you are going with `Action class` here for handling this `username` text box? – Jainish Kapadia Mar 01 '17 at 12:35
  • This is not the right way for practicing, your approach is totally wrong over here. Action class is used for drag and drop the element and hovering effect of the element to the use. – Jainish Kapadia Mar 01 '17 at 12:39
  • ok.. Thanks for pointing out. Will keep in mind.. – Rishabh Jain Mar 01 '17 at 12:40
  • hello, though you told me to xpath. ""driver.findElement(By.xpath("//table/../following::input[@name='userName']")).sendKeys("USERNAME");"" But my old xpath was also working. The problem was not in Xpath but in Grecko Driver. iused ChromeDriver and it worked so i accepted @enrique medina's answer – Rishabh Jain Mar 17 '17 at 10:19
  • Xpath was working but real problem was in grecko driver. – Rishabh Jain Mar 17 '17 at 11:02
  • @Rishabh I have seen that your `cssSelector` was wrong in your code. So the Issue is not related with action class, Issue is with your wrong css. It should be like that `driver.findElement(By.cssSelector("input[name='userName']"));` – Jainish Kapadia Mar 27 '17 at 11:34
  • So, I guess my this answer should get accepted, because i have provided valid `xpath` as well as valid `cssSelector`. – Jainish Kapadia Mar 27 '17 at 11:36
  • Have you notice your mistake in cssSelector? Your code = `input[name=userName]` and correct code = `input[name='userName']` – Jainish Kapadia Mar 27 '17 at 11:38
1

Explanation: Your cssSelector is incorrect, Use single quote for attribute value.

driver.findElement(By.cssSelector("input[name='userName']"));
Jainish Kapadia
  • 2,603
  • 5
  • 18
  • 29
Eknath
  • 624
  • 4
  • 11