当我在第一次迭代中运行for循环中的代码时,完美无缺。当第二次迭代开始时,我陷入了下面的代码行,说明元素不在位
wdd.FindElement(By.Id("loadLogin")).Click();
以下是我从main方法调用的函数。在这个我尝试导航到 paypal网站付款。第一次迭代很顺利。
public void PayPall()
{
wdd.FindElement(By.XPath("//input[@id='PayPalEmail']")).Click();
wdd.FindElement(By.XPath("//input[@id='PayPalEmail']")).SendKeys("padmini.soni@tritekconsulting.com");
wdd.FindElement(By.XPath("//input[@id='ConfirmPayPalEmail']")).SendKeys("padmini.soni@tritekconsulting.com");
wdd.FindElement(By.XPath("//button[@onclick='ValidateSubmit()']")).Click();
wdd.FindElement(By.Id("addAmount")).Click();
wdd.FindElement(By.Id("addAmount")).SendKeys("10");
wdd.FindElement(By.XPath("//input[contains(@src,'www.sandbox.paypal.com')]")).Click();
wdd.FindElement(By.Id("loadLogin")).Click();
Thread.Sleep(3000);
wdd.FindElement(By.Id("login_email")).SendKeys("rupali.shitole@outlook.com");
wdd.FindElement(By.Id("login_password")).SendKeys("Welcome01");
wdd.FindElement(By.Id("submitLogin")).Click();
wdd.FindElement(By.Id("continue")).Click();
}
在第二次迭代中,它进入同一个会话,并且不会获得click.Below的链接 我尝试查找并单击链接的代码。
wdd.FindElement(By.Id("loadLogin")).Click();
以下是我尝试调用PayPall()方法的主要方法代码。
for (rowCnt = 1; rowCnt <= range.Rows.Count; rowCnt++)
{
//str = (string)(range.Cells[rowCnt,colCnt] as Excel.Range).Value2;
//str = (string)(range.Cells[rowCnt, colCnt] as Excel.Range).Value;
string Charity = (string)(range.Cells[rowCnt, 1] as Excel.Range).Value;
string Country = (string)(range.Cells[rowCnt, 2] as Excel.Range).Value;
//System.Console.WriteLine(Charity + " --- " + Country);
wdd.Navigate().GoToUrl(baseURLL + "/");
//wd.Manage().Window.Size = new System.Drawing.Size(1366, 768);
Thread.Sleep(3000);
wdd.FindElement(By.Id("headerLoginLink")).Click();
wdd.FindElement(By.XPath("//input[@id='UserName']")).SendKeys("padmini.soni@tritekconsulting.com");
wdd.FindElement(By.Name("Password")).SendKeys("Welcome01");
wdd.FindElement(By.Id("loginButton")).Click();
wdd.FindElement(By.LinkText("Register a charity")).Click();
wdd.FindElement(By.XPath("//input[@name='Name']")).Click();
wdd.FindElement(By.XPath("//input[@name='Name']")).SendKeys(Charity);
//wd.FindElement(By.XPath("//input[@name='Name']")).SendKeys("Charityexample123");
wdd.FindElement(By.XPath("//button[@id='button0']")).Click();
wdd.FindElement(By.XPath("//button[@id='button3']")).Click();
wdd.FindElement(By.XPath("//button[@id='imagebutton']")).Click();
// wd.FindElement(By.Name("350x350.jpg")).SendKeys("C:\\Desktop\\350x350.jpg");
//wdd.FindElement(By.Name("350x350.jpg")).Submit();
System.Diagnostics.Process.Start("C:\\Work\\SeleniumDemo\\demo.exe");
System.Threading.Thread.Sleep(3000);
wdd.FindElement(By.XPath("//input[@id='AddressLine1']")).Click();
wdd.FindElement(By.XPath("//input[@id='AddressLine1']")).SendKeys("St John's Wood Rd");
wdd.FindElement(By.XPath("//input[@id='AddressLine2']")).Click();
wdd.FindElement(By.XPath("//input[@id='AddressLine2']")).SendKeys("Wood Rd");
wdd.FindElement(By.XPath("//input[@id='City']")).Click();
wdd.FindElement(By.XPath("//input[@id='City']")).SendKeys("London");
wdd.FindElement(By.XPath("//input[@id='Region']")).Click();
wdd.FindElement(By.XPath("//input[@id='Region']")).SendKeys(Country);
wdd.FindElement(By.XPath("//input[@id='PostalCode']")).Click();
wdd.FindElement(By.XPath("//input[@id='PostalCode']")).SendKeys("NW8 8QN");
//String country = "United Kingdom - British Pounds Sterling (£)";
//String country_selected = "United States - US Dollars ($)";
new SelectElement(wdd.FindElement(By.Id("CountrySelector"))).SelectByText(Country);
//SelectByText("United States - US Dollars ($)");
//String country = "United States - US Dollars ($)";
//new SelectElement(wd.FindElement(By.Id("CountrySelector")));
if (!Country.Equals("United States - US Dollars ($)"))
//if (country != "United States - US Dollars ($)")
//if (select != "United States - US Dollars ($)")
{
PayPall();
}
else
{
WePayy();
}
//System.Threading.Thread.Sleep(3000);
// wdd.FindElement(By.Id("headerLogoutLink")).Click();
wdd.Navigate().GoToUrl(baseURLL + "/");
wdd.FindElement(By.LinkText("LOG OUT")).Click();
Thread.Sleep(1000);
}//end of for loop