我需要使用selenium webdriver訪問文本框和按鈕id。由於它放置在contentplaceholder內,因此webdriver無法找到控件的標識。好心地建議我如何找到位於contentplaceholder內的控件。我想我需要爲此給路徑。你的想法會更有幫助。使用selenium webdriver訪問contentplaceholder屬性
這是我的aspx代碼:
<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>
我testproject代碼:
[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);
}
}
在此先感謝。