我使用SpecFlow、PhantomJS、Selenium和FluentAutomation.NET编写了几个测试。它们在Chrome和FireFox上运行良好,但当我在PhantomJS上运行时,它们失败了。
错误消息为:
元素当前不可交互,可能无法操作
搜索显示,这通常是由元素离开屏幕、页面未完全加载或其他随机故障引起的。插入等待并不能解决问题,设置.With.WindowSize(1980, 1080)
也不起作用。
代码非常简单,几乎直接来自样本
I.Focus(SearchInput);
I.Scroll(SearchInput);
I.Enter(searchText).In(SearchInput);
事实证明,通过Settings对象设置WindowWith
和~Height
会产生奇迹:
SeleniumWebDriver.Bootstrap(
SeleniumWebDriver.Browser.PhantomJs
);
FluentSettings.Current.WindowHeight = 1080;
FluentSettings.Current.WindowWidth = 1980;