私はC#を学び、配列について理解しようとしています。セレニウムC#で配列の実用的な使い方をしています。私の意図は、私はすべての価格を配列に格納し、forループを使ってコンソールで1つずつ反復することです。IWebElementsのリストを反復して配列に格納してからコンソールに印刷する方法#
namespace OneDimensionalarray
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = null;
driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
driver.Navigate().GoToUrl("http://www.shopclues.com/");
driver.FindElement(By.XPath("//input[@id='autocomplete']")). SendKeys("Lenovo");
driver.FindElement(By.XPath("//span[@id='search']/a")).Click();
IList<IWebElement> mobileprice = driver.FindElements(By.XPath("//span[@class='p_price']"));
//I want to store mobiles prices into an array and then print in the console.
int price = mobileprice.Count;
int[] prices = new int[price];
for (int i = 0; i < prices.Length; i++)
{
Console.WriteLine(price);
Console.Read();
}
}
}
}
どこにいらっしゃいますか?何かエラーがありますか?どの行? – DebanjanB
C#の初心者であればジェネリックスと 'List'について知ることができます。この型は配列と似ていると考えることができますが、要素を追加するとサイズが変更されます。 –
Scott
返事をありがとう。 エラーが表示されず、コンソールで価格を読み取ることもできません。 – user3884931