Answer the question
In order to leave comments, you need to log in
How to loop correctly?
private void button1_Click(object sender, EventArgs e)
{
IWebDriver driver;
FirefoxOptions options = new FirefoxOptions();
options.AddArguments("--headless");
driver = new FirefoxDriver(options);
driver.Url = "http://table.a.ru";
System.Threading.Thread.Sleep(600);
IWebElement table = driver.FindElement(By.XPath("/html/body/div[2]/table/tbody"));
string a = ")]";
string user = textBox1.Text; //введенный в текстбокс id сотрудника, который внедряем в xpath ниже
IWebElement oper = driver.FindElement(By.XPath("/html/body/div[2]/table/tbody/tr/td[contains(text()," + user + a));
string dobcount = oper.Text;
label2.Text = Convert.ToString(dobcount);
//Сотрудник
IList<IWebElement> findvalues = driver.FindElements(By.TagName("td"));
string res = "";
foreach (IWebElement values in findvalues)
{
res += values.Text + "/";
}
res = res.Substring(res.IndexOf(dobcount));
//res = res.Remove(res.IndexOf("tr"));
String[] td = res.Split(new char[] { '/' });
res = "Доб. " + td[0] + "\r\n" + " Сотрудник: " + td[1] + "\r\n" + " Пропущенные: " + td[3] + "\r\n" + " Принятые звонки: " + td[5] + "\r\n" + " В перерывах: " + td[14] + "\r\n" + " Текущий статус: " + td[15];
label3.Text = Convert.ToString(res);
System.Threading.Thread.Sleep(600);
}
Answer the question
In order to leave comments, you need to log in
You yourself write a dynamic label. This means that the size of the findvalues collection can change, and foreach does not like this, since it uses an enumerator, it checks for a change in the collection.
Try the usual for
for (int i = 0; i < findvalues.size(); i++)
{
res += findvalues[i].Text + "/";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question