如何使用“Text”类的“isTrue”方法?

时间:2013-07-17 07:08:09

标签: selenium selenium-webdriver

我无法使用文本类的“isTrue”方法

这是“文字”课程详情

http://selenium.googlecode.com/git/docs/api/java/index.html

//我编写的代码

public void researchSelenium(){

    driver.get(baseUrl);

    ConditionRunner.Context cont = new Research();
    Text obj = new Text("Why implement a customer referral program?");
    System.out.println(obj.isTrue(cont));

    driver.close();
    driver.quit();

我不知道该怎么做

ConditionRunner.Context cont = new Research(); //After "new" what should i write?

ConditionRunner.Context的对象将传递给“isTrue”方法

1 个答案:

答案 0 :(得分:0)

我将在这里做一些假设:

  • driver是一个selenium网络驱动程序实例
  • 您正试图查找网页中是否有文字字段
  • 你知道文本是什么,但不知道它的xpath(或者至少不关心它在哪里)。

在这种情况下,您只有轻微的语法错误

public void researchSelenium()
{
    driver.get(baseUrl);

    //Not sure what this is doing.
    ConditionRunner.Context cont = new Research();

    //Small chgange here
    string obj = "Why implement a customer referral program?";
    System.out.println(driver.isTextPresent(obj));

    driver.close();
    driver.quit();
}

NB。以上是“自由编码”,我没有测试/遵守它。如果有小问题,请随时编辑。

APPEND:

我个人会使用NUnit来处理测试,所以在这种情况下我会使用:

Assert.isTrue(driver.isTextPresent(obj));

要测试该文本是否确实存在,但是您运行测试的方式并不是您的问题所述。