同时打印两个ArrayList c#

同时打印两个ArrayList c#,c#,selenium,arraylist,C#,Selenium,Arraylist,我需要同时打印这两个阵列,但我想不出一个方法来完成 这是我的代码,它可以工作-现在如何添加数组名 ArrayList list = new ArrayList(); ArrayList name = new ArrayList(); list.Add("//*[@id=\"wrapper\"]/div[1]/div/header/div/h2"); name.Add("Projects Header"); list.Add("//*[@id=\"wrapper\"]/div[1]/div/

我需要同时打印这两个阵列,但我想不出一个方法来完成

这是我的代码,它可以工作-现在如何添加数组名

ArrayList list = new ArrayList();
ArrayList name = new ArrayList();

list.Add("//*[@id=\"wrapper\"]/div[1]/div/header/div/h2");
name.Add("Projects Header"); 

list.Add("//*[@id=\"wrapper\"]/div[1]/div/header/div/button/span[1]/span");
name.Add("Hamburger Menu");

list.Add("//*[@id=\"wrapper\"]/div[2]/div/div/div[2]/div[1]/div/div[1]/button");
name.Add("Create Project Button");

list.Add("//*[@id=\"wrapper\"]/div[2]/div/div/div[2]/div[1]/div/div[3]/button/span[1]");
name.Add("Join Project Button");



foreach (string xpath in list)
{             
    if (Driver.FindElement(By.XPath(xpath)).Size != null)
    {
        Console.WriteLine("element => " + xpath + " <= succesfully loaded!");                    
    }
}   
ArrayList list=new ArrayList();
ArrayList name=新的ArrayList();
添加(“//*[@id=\“wrapper\”]/div[1]/div/header/div/h2”);
名称。添加(“项目标题”);
添加(“//*[@id=\“wrapper\”]/div[1]/div/header/div/button/span[1]/span”);
名称。添加(“汉堡菜单”);
添加(“//*[@id=\“wrapper\”]/div[2]/div/div/div[2]/div[1]/div/div[1]/button”);
名称。添加(“创建项目按钮”);
添加(“//*[@id=\”wrapper\“]/div[2]/div/div/div[2]/div[1]/div/div[3]/button/span[1]”;
名称。添加(“加入项目按钮”);
foreach(列表中的字符串xpath)
{             
if(Driver.FindElement(By.XPath(XPath)).Size!=null)
{

WriteLine(“element=>”+xpath+”首先,我建议创建一个类:

class Model
{
    public string name { get; set; }

    public string attribute { get; set; }
}
之后,只需填充对象并将其放入列表中即可

List<Model> list = new List<Model>();

Model model = new Model();
model.name = "test";
model.attribute = "your Attribute";

foreach (var item in list)
{
     // you can get name and attribute here
     item.name;
     item.attribute;
}
List List=新列表();
模型=新模型();
model.name=“测试”;
model.attribute=“您的属性”;
foreach(列表中的变量项)
{
//您可以在这里获得名称和属性
项目名称;
项目属性;
}

希望这有帮助

你能写出你想要的结果吗?我不确定你想要什么为什么要使用两个单独的列表?为什么不让一个类有两个属性:
选择器
名称
,并将它们存储在一个
列表
(放弃未使用/未爱的
数组列表
)@TimageWepe我需要检查需要xpath的元素以确保它们不为空,我还需要显示我将为每个元素指定的名称,以便知道每个xpath对应的内容。示例:xpath1=“xxx”xpath1\u name=“this element“我想显示:xxx,其名称为该元素成功创建的名称loaded@MiguelAcosta这没有意义,这应该是一个
列表
(而不是
数组列表
)包含所需的两个属性的自定义类型。因此,如果要通过迭代元素来分配它们,为什么不创建一个同时包含这两个属性的类呢?然后创建对象并将它们添加到数组中。对于
属性
,不要使用
字符串
使用
by
,这样就不局限于一种定位器类型(例如,您可以通过.Id()使用
By
By.CssSelector()
,等等)。