2014-02-25 45 views
1

我遇到了Chromedriver无法在服务器上发送模拟输入(Control + P)的问题。我使用InputSimulator发送的输入(http://inputsimulator.codeplex.com/)。使用Selenium和Firefox,测试执行完美;但是,当我改变使用Chromedriver时,我遇到了我的输入模拟器在页面上没有正确触发的故障。这是唯一的区别。Chromedriver无法发送输入密钥

如果我在本地机器上而不是在服务器上执行测试,它会以完美的方式执行。由于InputSimulator只是模拟键被按下,它从不报告失败。

我在Windows Server 2008 R2 64位上运行的服务器。

为什么Selenium(Firefox)没有任何问题,现在改变为Chromedriver导致他们永远不会只发送一个服务器?代码更改的唯一部分是驱动程序设置。

硒(火狐)

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

请问为什么你需要这个库? – Arran

+0

我正在模拟手动打印,然后使用窗体窗体,我将文件路径发送到我希望保存的位置。我将它们保存为PDF文件,然后将它们转换为文本以查找一些值。在Firefox中,某些PDF不提供可选文本,但Chrome有一个“另存为PDF”选项,当Firefox不启用时,它提供可读的PDF。 – Ben

回答

0

InputSimulator不会在Windows Server工作2008 R2和Windows 7,如果Aero是关闭(我还没有与其他版本进行测试,还) 。

对于Windows 7,切换到Aero主题,它将重新开始工作。

对于Windows Server 2008 R2,你需要安装工作站的主题为航空:

  1. 运行此命令在命令提示符:

    ServerManagerCmd -i桌面,体验

  2. 重新启动服务器。

  3. 转到services.msc并启动Themes服务。

  4. 转到Windows显示设置,选择个性化,选择Aero主题。