使用System; 使用System.Text; 使用System.Collections.Generic; 使用System.Linq; 使用Microsoft.VisualStudio.TestTools.UnitTesting; 使用System.Text.RegularExpressions; 使用System.Threading; 使用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("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 + "]"));
}
}
}
}
测试方法Search1.SearchTest1.SearchMethod1抛出异常: Selenium.SeleniumException:错误:元素//输入[@ type ='checkbox'] [2]未找到
答案 0 :(得分:0)
尝试使用此代替selenium.IsChecked("//input[@type='checkbox'][" + i + "]")
:
selenium.IsChecked("/descendant-or-self::input[@type='checkbox'][" + i + "]")