Mario Mario - 1 year ago 190
C# Question

Selenium WebDriver: unable to locate element (C#)

I'm trying to automate Paypal withdrawals by using C# and 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). 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:

paypal form

I'm trying to click on the 'From' dropdown and among other things I've tried:



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

Guy Guy
Answer Source

You need to switch to the iframe first

IWebElement frame = driver.FindElement(By.TagName("iframe")); // locate the iframe element


And to switch back