使用 C# 进行 Selenium 测试:断言。为什么我会收到以下错误?
使用系统; 使用系统文本; 使用 System.Collections.Generic; 使用 System.Linq; 使用 Microsoft.VisualStudio.TestTools.UnitTesting; 使用 System.Text.RegularExpressions; 使用系统线程; 使用硒;
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:错误:元素 //input[@type='checkbox'][2] 未找到
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("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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用此代替
selenium.IsChecked("//input[@type='checkbox'][" + i + "]")
:Try using this instead of
selenium.IsChecked("//input[@type='checkbox'][" + i + "]")
: