[英]Selenium WebDriver: unable to locate element (C#)
I'm trying to automate Paypal withdrawals by using C# and Selenium. 我正在尝试通过使用C#和Selenium自动执行贝宝提现。 The application logs into Paypal using provided credentials and clicks on the 'transfer money' link, which then shows a pop-up (which looks to be an iframe).
该应用程序使用提供的凭据登录到Paypal,然后单击“转帐”链接,然后显示一个弹出窗口(看起来是iframe)。 My problem is that I can't click on any of the elements in the pop-up, and I've tried every suggestion I could find.
我的问题是我无法单击弹出式窗口中的任何元素,并且已经尝试了所有可以找到的建议。
Here is a screenshot of the form and the underlying html: 这是表单和基础html的屏幕截图:
I'm trying to click on the 'From' dropdown and among other things I've tried: 我尝试点击“发件人”下拉列表,以及其他尝试过的操作:
driver.FindElement(By.XPath("//*[@id=\"selection-container\"]/form/section/table/tbody/tr[2]/td/div[1]/div[1]")).Click();
and 和
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].hidden = false;", driver.FindElement(By.XPath("//*[@id=\"selection-container\"]/form/section/table/tbody/tr[2]/td/div[1]/div[1]")));
but either get and 'Unable to locate element' or 'Element not visible' errors. 但出现get和“无法找到元素”或“元素不可见”错误。 How do I get to the 'From' input element on the pop-up?
如何到达弹出窗口中的“发件人”输入元素? (If you're using paypal, you could also log in and take a peek at the pop-up if needed).
(如果您使用的是Paypal,也可以登录并根据需要查看弹出窗口)。
You need to switch to the iframe
first 您需要先切换到
iframe
IWebElement frame = driver.FindElement(By.TagName("iframe")); // locate the iframe element
driver.SwitchTo().Frame(frame);
driver.FindElement(By.XPath("//*[@id=\"selection-container\"]/form/section/table/tbody/tr[2]/td/div[1]/div[1]")).Click();
And to switch back 并切换回
driver.SwitchTo().DefaultContent();
Try 尝试
[FindsBy(How = How.CssSelector, Using = "div[class$='source-dropdown']")]
public IWebElement _ddSource;
The '$'
specifies the end of the attribute, in the case the end of the class is source-dropdown
如果类的末尾是
source-dropdown
,则'$'
指定属性的末尾
at first you need to switch to that iframe. 首先,您需要切换到该iframe。 use the below code:
使用以下代码:
IWebElement frame = driver.FindElement(By.CssSelector("iframe[src ='/moneytransfer']");
driver.SwitchTo().Frame(frame);
now you can click on that pop up by using this cssSelector: 现在,您可以使用以下cssSelector单击该弹出窗口:
div[class$='source-dropdown']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.