Identifying web elements

132 views
Skip to first unread message

Abhijit Khan

unread,
Apr 23, 2014, 9:09:34 AM4/23/14
to seleniu...@googlegroups.com
Hi,
Can anyone suggest a possible solution to identify the web elements in a html tag as below ?   It was supposed to be a simple one where you have the sign on screen and one should identify the username, password etc but seems none of the Find elements attributes seem to be working.
I tried with  the below but no luck.
            IWebElement username = driver.FindElement(By.Id("UserName"));
            IWebElement password = driver.FindElement(By.Id("Password"));

 Any suggestions ?
------------------------------------

<div id="login">           

            <h3 class="login-head">Log in with your  account details</h3>          

            <div>

                <input name="AeoMode" id="AeoMode" type="hidden" value="online">

                <label class="labelprimary" for="UserName">Email address:</label><p>

                <input name="UserName" id="UserName" type="text" maxlength="50" value="" data-val-required="Please enter a valid email address, e.g. your...@example.com" data-val-regex-pattern="^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$" data-val-regex="Please enter a valid email address, e.g. your...@example.com" data-val="true" cssclass="validate(email)" autocomplete="off"></p>

            </div>

            <div class="labelError">

                    <span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for="UserName"></span>

            </div>   

            <div>

                <label class="labelprimary" for="Password">Password:</label><p>

                <input name="Password" id="Password" type="password" maxlength="15" data-val-required="Your password must be at least 8 characters and contain 6 letters and at least two numbers or symbols" data-val="true" autocomplete="off"></p>               

            </div>

            <div class="labelError">

                    <span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for="Password"></span>

            </div>

            <div>              

                <div class="labelError" style="width: 85%; float: left;">

                </div>              

            </div>

             <div class="formRow" style="width: 85%;">      

                    <ul class="buttons" style="float: right;">

                        <li><input class="btn btnSmaller" type="submit" value="Log in"></li></ul>

                    <ul class="buttons" style="padding-right: 2em; float: right;">

                        <li><a class="cancel" id="ancBack" style="display: none;" href="/aeo/login" runat="server">Back</a></li></ul>

                        <p style="float: right;"><a id="ancResetPassword" href="https://www.aaaa.com.au/aeo/reset-password" target="_top" runat="server">Forgotten your password?</a></p>  

                </div>

          

        </div>

Abhijit Khan

unread,
Apr 29, 2014, 9:21:49 AM4/29/14
to seleniu...@googlegroups.com
surprisingly, if i record the session with Selenium ide and runs it , it identifies the elements and executes the scripts seamlessly.  When i save the same script in c# and execute from nunit, it fails to identify the elements.  The generated code also use a very similar FindBy attributes. Any thoughts will be helpful.

Cheers, 
Abhijit

Arunkumar K Suryanarayanan

unread,
Apr 29, 2014, 1:09:37 PM4/29/14
to seleniu...@googlegroups.com
The snippet that you have should have worked. Not sure why you aren't able to identify the elements. Have you tried with xpath?

driver.findElement(By.xpath("//input[@id='UserName']"));
driver.findElement(By.xpath("//input[@id='Password']"));

Hope this helps.

Cheers
Arun

NANI.THRINATH

unread,
Apr 30, 2014, 9:02:13 PM4/30/14
to seleniu...@googlegroups.com
Try with xpath!

 driver.findElement(By.xpath("//[@id='UserName']")).sendKeys("XYZ");
 driver.findElement(By.xpath("//[@id='Password']")).sendKeys("ABC");

Regards,
Thrinath


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/b1f24db3-ffb0-4cd9-9525-21a33e63f3ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Regards,
Thirnath

Afzal

unread,
May 1, 2014, 5:39:17 PM5/1/14
to seleniu...@googlegroups.com
Does this page has any Iframe 

Abhijit Khan

unread,
May 6, 2014, 9:11:24 AM5/6/14
to seleniu...@googlegroups.com
Hi All,
thanks for your responses. Yes, I tried with xpath and the same results.

Afzal - Yes, the login window uses iframe. Do we need a different treatment then ?

thanks,
Abhijit

santhosh soma

unread,
May 6, 2014, 9:50:22 AM5/6/14
to seleniu...@googlegroups.com
Yes. You need to switch to the frame and then do the actions.

To switch to the frame:
driver.switchTo.frame("Frame_ID");

To switch back to the main window:

driver.switchTo().defaultContent();

Thanks
Santhosh.



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages