|
用selenium IDE自动生成脚本如下:
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
namespace SeleniumTests
{
[TestFixture]
public class NewTest
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://change-this-to-the-site-you-are-testing/");
selenium.Start();
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void TheNewTest()
{
selenium.Open("/Product/ProductAdd.aspx");
selenium.Click("link=添加商品");
selenium.WaitForPageToLoad("30000");
selenium.Type("ctl00_ContentPlaceHolder1_ProductDetail_txtKeyValue", "a");
selenium.Select("ctl00_ContentPlaceHolder1_ProductDetail_drpManufacturer", "label=多普达");
selenium.Select("ctl00_ContentPlaceHolder1_ProductDetail_drpBrand", "label=DOPODO"); selenium.WaitForPageToLoad("30000");
selenium.Click("//img[@alt='选择商品分类']");
selenium.SelectFrame("popupFrame");
selenium.Click("//img[@alt='Expand 手机通讯']");
selenium.Click("//img[@alt='Expand 手机配件']");
selenium.Click("ctl00_ContentPlaceHolder1_CategoryTreeUC1_TreeViewCategoryn6CheckBox");
selenium.Click("ctl00_ContentPlaceHolder1_btnConfirm");
selenium.WaitForPageToLoad("30000");
selenium.SelectFrame("relative=up");
selenium.Type("ctl00_ContentPlaceHolder1_ProductDetail_txtItemName", "test20090204");
selenium.Type("ctl00_ContentPlaceHolder1_ProductDetail_txtItemDescription", "0204");
selenium.Type("ctl00_ContentPlaceHolder1_ProductDetail_txtPrice", "1000");
selenium.Type("ctl00_ContentPlaceHolder1_ProductDetail_txtDiscountPrice", "100");
selenium.Type("ctl00_ContentPlaceHolder1_ProductDetail_txtPrintDescription", "0204");
selenium.Type("ctl00_ContentPlaceHolder1_ProductDetail_txtLineDescription", "0204");
selenium.Click("ctl00_ContentPlaceHolder1_ProductDetail_btnSave");
selenium.WaitForPageToLoad("30000");
selenium.Click("alertButton");
selenium.Click("ctl00_ContentPlaceHolder1_ProductDetail_btnSave");
selenium.WaitForPageToLoad("30000");
selenium.Click("alertButton");
selenium.Click("chkItem");
selenium.Click("ctl00_ContentPlaceHolder1_ProductListUC_btnDown");
selenium.WaitForPageToLoad("30000");
selenium.Click("alertButton");
selenium.Click("//img[@alt='删除']");
selenium.Click("confirmOKButton");
selenium.WaitForPageToLoad("30000");
selenium.Click("alertButton");
}
}
}
当回放到("ctl00_ContentPlaceHolder1_ProductDetail_drpBrand", "label=DOPODO"); 时日志报错如下
[error] Option with label 'DOPODO' not found
原因是只有当选择生产商才能加载对应的品牌,如图
当我把代码改成("ctl00_ContentPlaceHolder1_ProductDetail_drpBrand", "label=请选择");这句代码就能通过了,需要高手帮忙解决当下拉菜单有关联关系时如何赋值才能加载我预期的目标值呢? |
|