我需要同时打印这两个数组,但是我找不到解决方法。
这是我的代码,它可以正常工作-现在如何添加数组名称?
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!");
}
}
答案 0 :(得分:2)
首先,我建议创建一个类:
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;
}
希望这会有所帮助