问题描述
我如何根据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();
和
sheet.getCell(3,3).cellClick();
但是它不起作用.预先感谢您提供任何解决方案或建议.
But it's not working. Thanks in advance if any solution or advice.
推荐答案
实际上,您需要做的是使用硒创建一个动作实例.例如,您可以让网络驱动程序打开Chrome,然后导航至以下示例之一:
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/");
然后使用getCellRect和SpreadJS宿主元素的偏移量计算当前页面的x/y坐标:
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;
然后,将鼠标移至单元格(在本例中为单元格D4)的中心位置:
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();
让我知道是否有帮助.
此致
传播团队
这篇关于用于测试SpreadJS的Selenium驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!