Search code examples
jqueryseleniumspreadjsgrapecity

Selenium driver for testing SpreadJS


How could I make click(events) on the basis of cell position in spreadJs? I try something like:

sheet.setActiveCell(3,3);
sheet.cellClick();

and

sheet.getCell(3,3).cellClick();

But it's not working. Thanks in advance if any solution or advice.


Solution

  • What you would need to do is essentially create an instance of an action using selenium. For example, you could have a web driver open Chrome, and navigate to one of our samples like so:

    var webDriver = new OpenQA.Selenium.Chrome.ChromeDriver();
    webDriver.Navigate().GoToUrl("https://www.grapecity.com/en/demos/spread/JS/ExcelMobileSample/");
    

    Then calculate the x/y coordinates for the current page by using getCellRect and the offset of the SpreadJS host element:

    var cellRect = sheet.getCellRect(3, 3);
    var host = spread.getHost();
    var offset = $(host).offset();
    cellRect.x += offset.left + cellRect.width / 2;
    cellRect.y += offset.top + cellRect.height / 2;
    

    Then you would move the mouse to the center position of a cell (in this case, cell D4):

    var action = new OpenQA.Selenium.Interactions.Actions(webDriver);
    action.MoveByOffset(x, y);
    

    And then finally click on that cell:

    action.Click();
    action.Perform();
    

    Let me know if that helps.

    Regards,

    Spread Team