简体   繁体   中英

PayPal Sandbox checkout 'continue button' - Unable to locate element: - C# WebDriver

I've taken a good look around, however haven't been able to find the specific answer i'm after; hoping someone is able to point me in the right direction.

I'm automating a PayPal checkout process with WebDriver 2.53 in Visual Studio 2015 using C# against the Firefox driver. My flow into PayPal is fine, being able to login through the sandbox environment. However when I get to the confirmation screen following the initial login, I appear to be unable to select the continue button.

在此处输入图片说明

My code is:

driver.SwitchTo().Frame(driver.FindElement(By.TagName("iframe")));
var emailAddressLogin = driver.FindElement(By.Id("email"));
emailAddressLogin.SendKeys("EMailAddress");
var password = driver.FindElement(By.Id("password"));
password.SendKeys("Password");
var login = driver.FindElement(By.Id("btnLogin"));
login.Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
var ContinueButton = driver.FindElement(By.XPath("//*[@id=\"confirmButtonTop\"]"));
ContinueButton.Click();

Once it gets to the confirmButtonTop selection, I'm always returning:

An exception of type 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll but was not handled in user code. Additional information: Unable to locate element: {"method":"id","selector":"confirmButtonTop"}

I have tried to locate the button via XPath, ID etc but nothing seems to allow the selection and always returned with "Unable to locate element".

HTML

Has anyone had issues with the 'continue' button within the PayPal sandbox environment, or advise what i'm missing? I have tried to switch focus but this doesn't seem to work.

Ok so having done a little more searching I have found that by adding the following to my code before the button selection to work:

driver.SwitchTo().Window(driver.WindowHandles.Last());

So the end code looked like:

driver.SwitchTo().Frame(driver.FindElement(By.TagName("iframe")));
var emailAddressLogin = driver.FindElement(By.Id("email"));
emailAddressLogin.SendKeys("EMailAddress");
var password = driver.FindElement(By.Id("password"));
password.SendKeys("Password");
var login = driver.FindElement(By.Id("btnLogin"));
login.Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
driver.SwitchTo().Window(driver.WindowHandles.Last());
var ContinueButton = driver.FindElement(By.XPath("//*[@id=\"confirmButtonTop\"]"));
ContinueButton.Click();

This was taken from Selenium webdriver selecting new window c# and thanks to joinsaad

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM