I need to access the textbox and button ids using selenium webdriver. Since it is placed inside contentplaceholder, webdriver is not able to find the id of the controls. kindly suggest me how to find the controls which are inside the contentplaceholder. i guess i need to give path for this. Your idea will be more helpful.
This is my aspx code:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<table>
<tr>
<td> <asp:Label ID="lblName" runat="server" Text="Name :" ></asp:Label> </td>
<td> <asp:TextBox ID="txtName" runat="server"
ToolTip="Enter your registered user name"></asp:TextBox> </td>
</tr>
<tr>
<td> <asp:Label ID="lblPwd" runat="server" Text="Password :" ></asp:Label> </td>
<td> <asp:TextBox ID="txtPwd" runat="server"
ToolTip="Enter your registered password"></asp:TextBox> </td>
</tr>
<tr>
<td>
<asp:Button ID="btnLogin" runat="server" Text="Login" onclick="btnLogin_Click"
ToolTip="Click to Login"/> </td>
<td> <asp:Label ID="lblWarning" runat="server" Text=" "></asp:Label> </td>
</tr>
</table>
</asp:Content>
My testproject code is:
[TestMethod()]
public void TestMethod1()
{
//try
//{
driver.Navigate().GoToUrl("http://localhost:50294/Login.aspx");
driver.FindElement(By.Id("txtname")).SendKeys("sachin");
driver.FindElement(By.Id("btnLogin")).Click();
Label lbl = page.FindControl("lblWarning") as Label;
Assert.AreEqual(lbl, "Inserted successfully");
}
catch (Exception er)
{
Assert.Fail(er.Message);
}
}
Thanks in advance.
Thanks for your reply. But it’s not working in my case.
However i could able to find a solution for my issue.
I replaced the textbox and button controls’ ids by the ids which are dynamically generated in the browser in the page source option. now web driver can able to find those controls and inserting values into the textbox.
This is my new code:
The above code works fine 🙂