Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java isTextPresent在Selenium测试中始终失败。不确定我是否做错了什么_Java_Selenium - Fatal编程技术网

Java isTextPresent在Selenium测试中始终失败。不确定我是否做错了什么

Java isTextPresent在Selenium测试中始终失败。不确定我是否做错了什么,java,selenium,Java,Selenium,我有一段代码,它只检查页面上某个位置的特定文本,如果找到该文本,它将检查其他内容。以下是代码片段: 如果!selenium.isTextPresent//div[containsconcat、@class、'contentLg']/h2{ System.out.println关于美国的文本不存在; } 否则{ verifyEqualsaboutText,//*[@class='content contentLg']/p[3]; } 这里是我试图从中获取关于我们的文本的生成输出。我试图看看网页是否

我有一段代码,它只检查页面上某个位置的特定文本,如果找到该文本,它将检查其他内容。以下是代码片段:

如果!selenium.isTextPresent//div[containsconcat、@class、'contentLg']/h2{ System.out.println关于美国的文本不存在; } 否则{ verifyEqualsaboutText,//*[@class='content contentLg']/p[3]; }

这里是我试图从中获取关于我们的文本的生成输出。我试图看看网页是否有关于我们的文本,这是在标签。如果有,只需将其中一个p标记与预定义文本匹配即可:

 <!-- MAIN CONTENT CONTAINER -->
关于我们


下面是我在扩展DefaultSelenium的CustomSelenium类中编写的内容

public boolean waitForTextPresent(final String text, long timeout) {
    Wait wait = new Wait() {

        @Override
        public boolean until() {
            try {
                return CustomSelenium.this.isTextPresent(text);
            } catch (SeleniumException e) {
                return false;
            }
        }
    };
    try {
        wait.wait("Error: text " + text + " not present in the page", timeout, 50);
    } catch (NumberFormatException e) {
        log.error(e.getMessage(), e);
        throw e;
    } catch (WaitTimedOutException e) {
        log.warn(e.getMessage(), e);
        return false;
    }
    return true;
}
在打电话给isTextPresent之前先打这个电话。这是

public boolean waitForTextPresent(final String text, long timeout) {
    Wait wait = new Wait() {

        @Override
        public boolean until() {
            try {
                return CustomSelenium.this.isTextPresent(text);
            } catch (SeleniumException e) {
                return false;
            }
        }
    };
    try {
        wait.wait("Error: text " + text + " not present in the page", timeout, 50);
    } catch (NumberFormatException e) {
        log.error(e.getMessage(), e);
        throw e;
    } catch (WaitTimedOutException e) {
        log.warn(e.getMessage(), e);
        return false;
    }
    return true;
}