【问题标题】:Using assertEqual and getElementbyxpath in Junit Selenium在 Junit Selenium 中使用 assertEqual 和 getElementbyxpath
【发布时间】:2012-10-06 10:18:35
【问题描述】:

我基本上是在编写一个测试用例来确定在 Facebook 上共享的状态是否真的被共享。下面是获取 Facebook 上第一篇文章文本的 xpath。我想将其与我发布的状态进行比较,例如“Blah”。我一直在尝试使用 AssertEquals 但这似乎不起作用。

 WebElement status = getElement(By.Xpath("//div[@id='pagelet_home_stream']//ul[@id = 'home_stream']//li[1]//span[@class='userContent']")

 AssertEquals(status, "Blah");

【问题讨论】:

  • 可能是时间问题。看到这个帖子:stackoverflow.com/questions/5817185/…
  • 你能显示更多的代码吗? assertEquals(),如何获取元素的值。 XPath 表达式本身看起来不错。
  • 添加了 AssertEquals 语句。

标签: junit selenium-webdriver


【解决方案1】:

您需要调用element.getText(),否则您将与WebElement 对象而不是String 进行比较。此外,在 assertEquals(expected, actual) 中将预期文本放在首位也很重要,否则当它们不匹配时,您会收到一条令人困惑的消息。

assertEquals("Blah", status.getText());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多