1

New at Selenium (C#). Wanted to automate some third party page login. When I navigate manually and in chrome F12 > "View Element", I see the text boxes good.

<input type="text" id="username" name="username" >
<input type="password" id="password" name="password" >

However, when I do "View Source" I don't see that. I assume there is Javascript code that generates this login form.

In Selenium - it works on the "View Source" version of course - when I do the following I get - "No Such Element" as expected...

var x = Driver.FindElement(By.Name("username"));

Is it possible for Selenium to interacts with fields that were generated dynamically like in my case? Like tell it to "wait" or dive to the dynamic version of the html or something?

3
  • 1
    Are you sure there are no iframes on the page? Commented Jan 12, 2015 at 20:47
  • not so familiar with IFrame, but you're right there are IFrames...don't see a place I can get a hold and fill the fields in these iframes... Commented Jan 12, 2015 at 20:51
  • ok you are absoulutly right - this is IFrame so I went to the IFrame page and now I'm able to interact with the fields. many thanks!! Commented Jan 12, 2015 at 20:55

1 Answer 1

1

In case the target element is not inside an iframe, then using an Explicit Wait should solve the problem:

IWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3));
IWebElement element = wait.Until(ExpectedConditions.ElementExists(By.Id("username")));

See also: Selenium c# Webdriver: Wait Until Element is Present

If the element is inside an iframe, you should first switch to it:

IWebElement frame = driver.FindElement(By.Id("my_frame_id"));
driver.SwitchTo().Frame(frame);

See also: Finding nested iFrame using Selenium 2

Sign up to request clarification or add additional context in comments.

2 Comments

this is so cool - is it fair to say that if selenium waits - its source will be updated with all the generated content?
@user1025852 you can say so, in this case the webdriver would periodically ask for the element (polling) until a timeout (3 seconds in the example). As far as I recall, the default polling interval is 500 milliseconds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.