【发布时间】:2015-02-09 21:54:53
【问题描述】:
当我登录机器运行 exe 时,脚本工作正常。但是当我在 VisualCron 上安排 .exe 时,它会引发异常。我在 Windows 调度程序上尝试了相同的 .exe,我能够运行该作业。
错误详情如下。我该如何解决这个问题。请帮忙。
代码:
using log4net;
using Microsoft.VisualStudio.TestTools.UITest.Common;
using Microsoft.VisualStudio.TestTools.UITest.Extension;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Support.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace SeleniumDocManager
{
class To_Run_IE
{
private static ILog log;
static void ConfigureLog4Net()
{
log4net.GlobalContext.Properties["applicationname"] = "Selenium";
log4net.Config.XmlConfigurator.Configure();
log = LogManager.GetLogger(System.Reflection.Assembly.GetExecutingAssembly().GetType());
}
static string CreateFileFolder()
{
//Environment.CurrentDirectory = "C:\\myCSharp\\mySelenium";
Environment.CurrentDirectory = "E:\\Jobs\\Visualcron\\QA\\myInfoCenter";
string foldername = Path.Combine(Environment.CurrentDirectory, DateTime.Now.ToString("yyyy-MM-dd"));
if (!Directory.Exists(foldername))
{
Directory.CreateDirectory(foldername);
}
return foldername;
}
static void Main(string[] args)
{
ConfigureLog4Net();
string todayFolder = CreateFileFolder();
string programOutputPath = Path.Combine(todayFolder, "ProgramOutput.txt");
IWebDriver driver = new InternetExplorerDriver();
using (System.IO.StreamWriter file = new System.IO.StreamWriter(programOutputPath, true))
{
file.WriteLine("Starting Test, page title is: " + driver.Title);
}
string outputpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Console.Write ("outputpath is :" + outputpath + " ");
log.Debug("Starting Test, page title is: " + driver.Title);
System.Console.WriteLine("Starting Test, page title is: " + driver.Title);
System.Console.WriteLine("Page source is: " + driver.PageSource);
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("http://cf-qa-web01:100/Home/Attachments/B1C56889-54D6-E211-ACC3-0050569D4561");
System.Threading.Thread.Sleep(5000);
By byXpath = By.XPath("//select[@id='DocumentType']");
System.Threading.Thread.Sleep(5000);
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists(byXpath));
IWebElement element = driver.FindElement(byXpath);
var selectElement = new SelectElement(element);
int options = selectElement.Options.Count;
System.Threading.Thread.Sleep(5000);
Screenshot s0 = ((ITakesScreenshot)driver).GetScreenshot();
System.Threading.Thread.Sleep(5000);
s0.SaveAsFile(Path.Combine(todayFolder, string.Format("{0}_{1:yyyy-MM-dd_HH-mm-ss}.jpeg", "Document_Manager_Initial_Screenshot", DateTime.Now)),
System.Drawing.Imaging.ImageFormat.Gif);
System.Threading.Thread.Sleep(2000);
try
{
Console.WriteLine(selectElement.Options[0].Text);
using (System.IO.StreamWriter file = new System.IO.StreamWriter(programOutputPath, true))
{
file.WriteLine("Capture @ " + selectElement.Options[0].Text);
}
string _getssName = selectElement.Options[0].Text;
//new SelectElement(driver.FindElement(byXpath)).SelectByIndex(0);
Console.WriteLine("Capturing " + "Select Document Type" + " dropdown screenshot");
System.Threading.Thread.Sleep(5000);
Screenshot sss = ((ITakesScreenshot)driver).GetScreenshot();
System.Threading.Thread.Sleep(5000);
sss.SaveAsFile(Path.Combine(todayFolder, string.Format("{0}_{1}_{2:yyyy-MM-dd_HH-mm-ss}.jpeg", " Select Document Type ", "dropdown", DateTime.Now))
错误详情:
未处理的异常:OpenQA.Selenium.UnhandledAlertException:OpenQA.Selenium.Remote.RemoteWebDriver.Execute(字符串 driverCommandToExecute,Dictionary`2 参数)的 OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(响应错误响应)出现模态对话框SeleniumDocManager.To_Run_IE.Main(String[] args) 处的 .Selenium.Remote.RemoteWebDriver.GetScreenshot() 任务中的异常:非零退出代码
【问题讨论】:
-
错误表示有某种对话框被抛出,它不喜欢它。不过在这里检查解决方案:stackoverflow.com/questions/25991089/…