我已经用硒c#进行了自动化测试,并有一个probelm。我的测试在表单中写入一些信息,然后提交,如果在提交包含一些信息的div的信息“Formoje yra klaidu”后,它必须写入文件电子邮件从表单,但问题是,这个div不可见时,电子邮件isn' t错了,我的测试只是停止在Iwebelement通过xpath找到元素的地方,因为元素不可见。这里的一些代码硒c#自动化测试
for (int i = 0; i < array.Length; i++)
{
IWebElement PasirinktiParkinga = driver.FindElement(By.CssSelector("#zone_16 > td:nth-child(5) > a:nth-child(1)"));
PasirinktiParkinga.Click();
IWebElement Vardas = driver.FindElement(By.Id("firstname1"));
Vardas.Clear();
Vardas.SendKeys("Vardas");
IWebElement Pavarde = driver.FindElement(By.Id("lastname1"));
Pavarde.Clear();
Pavarde.SendKeys("Pavarde");
IWebElement AutoNumeris = driver.FindElement(By.Id("vehicle_number1"));
AutoNumeris.Clear();
AutoNumeris.SendKeys("ASD123");
IWebElement Pastas = driver.FindElement(By.Id("email1"));
Pastas.Clear();
Pastas.SendKeys(array[i]);
IWebElement Taisykles = driver.FindElement(By.CssSelector("div.checks:nth-child(5) > div:nth-child(1) > label:nth-child(2)"));
Taisykles.Click();
IWebElement uzsakyti = driver.FindElement(By.CssSelector(".submit-zone > input:nth-child(1)"));
uzsakyti.Click();
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
IWebElement MessageRed = driver.FindElement(By.XPath("//*[@id='step_2']/div[3]")); //This line is were i wan't to find this div but i must write it so that if there isn't there - just do the for cicle
if (MessageRed.Text.Contains("Formoje yra klaidų."))
{
failure += array[i] + "\n";
System.IO.File.WriteAllText(@"C:\Users\jarek\Desktop\Failureemail\failure.txt", failure);
}
IWebElement unipark = driver.FindElement(By.CssSelector(".logo > a:nth-child(1)"));
unipark.Click();
i++;
}
如何使这个元素不存在,代码不会停止。 任何机构都可以帮助我?
找到一个元素的方法,我不知道为什么,但是这不是为我工作 – 2015-04-01 08:24:22