moveToElement(element,xoffset,yoffset) not working in selenium webdriver 2.32.0

36,664

Solution 1

I had the same issue. Using ClickAndHold() and Release() worked when Click() did not. I also like using percentages on any x,y coordinates so they are relative. May or may not help you. C# below.

        IWebElement MarkAs = MarkAsSpan(driver).FindElement(By.Id("btnMarkAs"));
        int Width = MarkAs.Size.Width;
        int Height = MarkAs.Size.Height;
        int MyX = (Width * 95) / 100;//spot to click is at 95% of the width
        int MyY = 1;//anywhere above Height/2 works
        Actions Actions = new Actions(driver);
        Actions.MoveToElement(MarkAs,MyX,MyY);
        Actions.ClickAndHold();
        Actions.Release();
        Actions.Perform();

Solution 2

Similar problem i solved by using below code may be this helpful for you,Try first find out the x and y offset.

    driver= new FirefoxDriver();
    driver.manage().window().maximize();
    driver.get("http://dev.sencha.com/deploy/ext-4.0.0/examples/toolbar/toolbars.html");
    driver.findElement(By.xpath("//em")).click();   
    System.out.println(driver.findElement(By.xpath("//em")).getSize());
    Actions action = new Actions(driver);
    action.moveToElement(driver.findElement(By.xpath("//em")), 97, 16).click().build().perform();
Share:
36,664
Mrunal Gosar
Author by

Mrunal Gosar

I am a passionate automation developer having proficiency in testing AI and Data Analytics based web, desktop and middleware applications using Java / Python / C#. I also have expertise in DevOps and providing CI & CD solutions.

Updated on October 07, 2020

Comments

  • Mrunal Gosar
    Mrunal Gosar over 3 years

    I am trying to use moveToElement(element,xoffset,yoffset) of the Actions class in selenium web driver (java) in FireFox 21. but it seems it is not working. I have a extjs button control which acts as button as well as drop down(please refer screen shots).

    extjs button cum drop down control

    When i click on the Save Changes section it saves the changes and when i am clickin on the drop down button attached to it, it opens up the list. please refer the DOM source for the same control.

    <td class="x-btn-mc"><em id="ext-gen514" class="x-btn-split" unselectable="on"><button id="btn-ext-comp-1739" class=" x-btn-text save-changes" type="button"><u>
          S
        </u>
          ave Changes
        </button></em></td>
    

    Now i am able to click on the Save Changes button but i am not able to click on the drop down button by giving some offset position in the moveToElement method.

    I have tried below two options:

    1. builder.moveToElement(element).moveByOffset(569, 5).click().build().perform();
    2. builder.moveToElement(element, 568, 5).click().build().perform();

    but both are not working.

    The dimensions of the control are (117 x 16)

    Note: do not get confused by offsets 568,5 as this offsets are still able to click on the save changes button.

    Is it that this method is not yet supported in latest web driver?

  • Mrunal Gosar
    Mrunal Gosar about 11 years
    i am using the same actions class. but my problem is i want to click on the drop down button of the Save Changes control which will show me the drop down list(containing control shown in the second image). for this i tried using moveToElement of the actions class but it is not working i guess. can u suggest some workaround for this
  • Kapil
    Kapil about 11 years
    I have added few lines here again. check it now
  • Mrunal Gosar
    Mrunal Gosar about 11 years
    i dont find element with class name as badgeFeatured neither a element with css as (#headerMenu .subLink). Any other workarounds?
  • Mrunal Gosar
    Mrunal Gosar about 11 years
    please see above, the html code is there where we have <td><em><button> tags.
  • Mrunal Gosar
    Mrunal Gosar about 11 years
    i have used the same thing but it is not working. i guess the issue is with the method itself, it has not been implemented properly. any other workarounds to achieve that? which version of selenium and Firefox you were using can u share so that i can try porting to that version and try the same.
  • Omkar
    Omkar about 11 years
    I am using Firefox 21.0 with Win 7.Have you get x and y offset using .get size method.
  • Omkar
    Omkar about 11 years
    @Mrunal I am using Selenium Web-driver 2.32.0 version
  • Mrunal Gosar
    Mrunal Gosar about 11 years
    yes the dimensions are : (117 X 16) i have tried following offsets : (117 X 16),(115 x 10),(110 x 5),(568 x 0),(568 x 10). all this offset combinations are directly clicking on the Save changes button and not on the inverted triangle to show the drop down list
  • Doug
    Doug almost 10 years
    Watch out for case sensitivity with names like findElement. In C# it is FindElement.
  • Suraj Gupta
    Suraj Gupta over 7 years
    The first line is showing up an error to me **'object doesnot contain a definition for 'FindElement' accepting first argument of type 'object' could be found