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

限于喜欢 提交于 2020-01-07 02:54:10

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/39492424/paypal-sandbox-checkout-continue-button-unable-to-locate-element-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!