我遇到Chromedriver无法在服务器上发送模拟输入(Control + P)的问题。我使用InputSimulator(http://inputsimulator.codeplex.com/)发送的输入。使用Selenium和Firefox,测试执行完美;然而,当我改用以使用Chromedriver时,我遇到输入模拟器的故障,而不是在页面上正确触发。这是唯一的区别。
如果我在本地计算机而不是服务器上执行测试,它将执行完美无缺。由于InputSimulator只是模拟按下它们的键,它从不报告失败。
我在Windows Server 2008 R2 64 Bit上运行的服务器。
为什么Selenium(Firefox)没有任何问题,现在更改为Chromedriver会导致他们永远不会只发送一个服务器?代码更改的唯一部分是驱动程序设置。
Selenium(firefox)
FirefoxProfile profile = new FirefoxProfile(@"path/to/profile");
using (IWebDriver driver= new FirefoxDriver(profile))
{
//Navigate to URL
driver.Navigate().GoToURL(@"http://google.com");
//Wait for the page to load
Thread.Sleep(2000);
InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_P);
Thread.Sleep(2000);
InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
//Now I have the dialog to send my save path.
}
Chromedriver
var options = new ChromeOptionsWithPrefs();
options.prefs = new Dictionary<string, object>
{
{ "printing.print_preview_sticky_settings.appState","{\"version\":2,\"isGcpPromoDismissed\":false,\"selectedDestinationId\":\"Save as PDF\",\"selectedDestinationOrigin\":\"local\",\"customMargins\":null}" }};
options.AddArgument("--disable-extensions");
options.AddArgument("-incognito");
options.AddArgument("-start-maximized");
options.AddArgument("--renderer-print-preview");
using (IWebDriver driver= new ChromeDriver(@"C:/Chromedriver/path", options))
{
//Navigate to URL
driver.Navigate().GoToURL(@"http://google.com");
//Wait for the page to load
Thread.Sleep(2000);
InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_P);
//Code never fires on the servers; does fire on my local machine.
Thread.Sleep(2000);
}
答案 0 :(得分:0)
如果Aero关闭,则InputSimulator在Windows Server 2008 R2和Windows 7中不起作用(我还没有测试过其他版本)。
对于Windows 7,切换到Aero主题,它将重新开始工作。
对于Windows Server 2008 R2,您需要安装Aero的工作站主题:
在命令提示符下运行此命令:
ServerManagerCmd -i桌面体验
重启服务器。
转到services.msc并启动Themes服务。
转到Windows显示设置,选择个性化,选择航空主题。