本文介绍了贝宝沙盒结帐“继续按钮"-无法找到元素:-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.

我正在使用C#针对Firefox驱动程序在Visual Studio 2015中使用WebDriver 2.53自动执行PayPal结帐过程.我进入Pay​​Pal的流程很好,能够通过沙盒环境登录.但是,当我在首次登录后进入确认屏幕时,似乎无法选择继续按钮.

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.

我的代码是:

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();

一旦进入confirmButtonTop选择,我总是返回:

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

我试图通过XPath,ID等来定位按钮,但是似乎没有允许选择的内容,并且总是返回无法定位元素".

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

在PayPal沙箱环境中,是否有人对继续"按钮有疑问,或者告诉我我所缺少的是什么?我试图切换焦点,但这似乎不起作用.

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());

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

所以最终代码如下:

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();

这取自 Selenium webdriver选择新窗口c#,感谢joinsaad

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

这篇关于贝宝沙盒结帐“继续按钮"-无法找到元素:-C#WebDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 16:33