【问题标题】:Capture strings and pass it into an argument as a List<string>捕获字符串并将其作为 List<string> 传递给参数
【发布时间】:2020-08-31 15:33:12
【问题描述】:

我在 try catch 中有几个字符串,它们使用相同的变量 location

try
{
    IWebElement bi7_reportHolder = ieDriver.FindElement(By.ClassName("iframe-qlik-view"));
    //Check if Pop-up is present
    location = ssLocation["SaveScreenShotLocation"] + "bi7_ScreenShot.png";
    CheckPopUpAndTakeScreenShot(ieDriver, executor, location);
}
catch (System.Exception e)
{
    Console.WriteLine(e.Message);
}


//Open bi8 Report - Concentration Risk
ieDriver.Navigate().GoToUrl("https://insightsmp.accenture.com/reports/9615a4f8-765f-4bed-9ccd-f8fa7cf3cbae/");
Thread.Sleep(60000);
wait.Until(d => ((IJavaScriptExecutor)d).ExecuteScript("return document.readyState").Equals("complete"));
try
{
    IWebElement bi8_reportHolder = ieDriver.FindElement(By.Id("reportParent"));
    //Check if Pop-up is present
    location = ssLocation["SaveScreenShotLocation"] + "bi8_ScreenShot.png";
    CheckPopUpAndTakeScreenShot(ieDriver, executor, location);
}
catch (System.Exception e)
{
    Console.WriteLine(e.Message);
}

//Open Detailed Reporting
ieDriver.Navigate().GoToUrl("https://insightsmp.accenture.com/detailedReporting/");
Thread.Sleep(60000);
wait.Until(d => ((IJavaScriptExecutor)d).ExecuteScript("return document.readyState").Equals("complete"));
try
{
    IWebElement dr_reportHolder = ieDriver.FindElement(By.Id("search-bar"));
    //Check if Pop-up is present
    location = ssLocation["SaveScreenShotLocation"] + "DR_ScreenShot.png";
    CheckPopUpAndTakeScreenShot(ieDriver, executor, location);
}
catch (System.Exception e)
{
    Console.WriteLine(e.Message);
}

我需要捕获所有这些字符串并将其作为 List 参数传递给我正在调用的方法,以便我可以在方法中使用它们。

List<string> screenshotLocation = location.ToString();

SendEmail(Application, screenshotLocation, bi6Accessible, bi7Accessible, bi8Accessible, detailedReportingAccessible);

我该怎么做?

【问题讨论】:

  • 你快到了。创建一个列表,然后将add 字符串传递给它。完成。

标签: c# string selenium arraylist c#-4.0


【解决方案1】:

在您的第一个try 语句之上,初始化您的列表。

List<string> screenshotLocation = new List<string>();

然后,每次设置 location 变量时,将其添加到该列表中,就像这样。

location = ssLocation["SaveScreenShotLocation"] + "bi7_ScreenShot.png";
screenshotLocation.Add(location);
//other code

然后,当调用您的 SendEmail 方法时,列表已准备好添加值。你可以像拥有它一样调用它。 (假设其他变量也正确)

【讨论】:

    猜你喜欢
    • 2015-11-20
    • 2019-08-05
    • 2014-04-06
    • 2013-12-04
    • 2013-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    相关资源
    最近更新 更多