圣诞节交付
请尽量在11月24日之前下订单以避免圣诞邮件延误
我想在页面上测试上面的文字..检查我的编码我一直认为测试失败
var notice2 = driver.FindElement(By.XPath("/html/body/form[@id='aspnetForm']/div[@class='wrapper']/div[@class='wrapper_inside ']/div[@class='content_right']/div[@class='scn_full']/div[@class='special_panel'][2]/div[@class='special_holder']/div[@class='special_block']/div[3]"));
Assert.IsTrue(driver.PageSource.Contains("Please try to have your order placed by November 25th to avoid Christmas postal delays"));
答案 0 :(得分:1)
如果你发布了杰夫提到的html会更好。你的xpath非常脆弱,所以我建议修复它。
基本上你想要做的是:
获取元素的文本值:
var notice2 = driver.FindElement(By.XPath("//myNewXPath")).Text;
然后断言值相等:
Assert.AreEqual(notice2, "Please try to have your order placed by November 25th to avoid Christmas postal delays");