Selenium testing using C#: assertions. Why am I getting the following error?
using System; using System.Text; using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Text.RegularExpressions; using System.Threading; using Selenium;
namespace Search1
{
[TestClass]
public class SearchTest1
{
public SearchTest1()
{
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
private ISelenium selenium;
[TestMethod]
public void SearchMethod1()
{
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://localhost/crm.aspx");
selenium.Start();
selenium.Open("/crm/SearchPage.aspx?function=3");
selenium.WaitForPageToLoad("30000");
Assert.IsTrue(selenium.IsTextPresent("开发者_Go百科Select All | Clear All"));
try
{
Assert.IsTrue(selenium.IsTextPresent("Select All | Clear All"));
}
catch (Exception)
{
}
selenium.Click("//span[@onclick=\"fnCheckGroupWithMessage('You have selected all items.', 'cbxRepeater_');\"]");
Assert.AreEqual("'You have selected all items.", selenium.GetAlert());
decimal totalCheckboxes = selenium.GetXpathCount("//input[@type='checkbox']");
for (int i = 1; i < totalCheckboxes + 1; i++)
{
Assert.IsTrue(selenium.IsChecked("//input[@type='checkbox'][" + i + "]"));
}
}
}
}
Test method Search1.SearchTest1.SearchMethod1 threw exception: Selenium.SeleniumException: ERROR: Element //input[@type='checkbox'][2] not found
Try using this instead of selenium.IsChecked("//input[@type='checkbox'][" + i + "]")
:
selenium.IsChecked("/descendant-or-self::input[@type='checkbox'][" + i + "]")
精彩评论