Selenium getText不适用于标记名为h2的元素

Selenium getText不适用于标记名为h2的元素,selenium,gettext,Selenium,Gettext,我试图从标记名h2读取元素的文本,结果返回空值 <div id="informationModal" class="modal fade in" role="dialog" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-hidden="false" style="display: block; padding-right: 16px;"> <div class="modal-md

我试图从标记名h2读取元素的文本,结果返回空值

<div id="informationModal" class="modal fade in" role="dialog" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-hidden="false" style="display: block; padding-right: 16px;">
        <div class="modal-md modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h1 class="modal-title">Message</h1>
                </div>
                <div class="modal-body">
                    <h2 style="font-size:17px;">
                        Request cannot be processed. Access denied, read only.
                    </h2>
                </div>
                <div class="modal-footer">
                    <button id="cancelinformation" class="btn-cancelconfirm btn btn-default" data-dismiss="modal">OK</button>
                </div>
            </div>
        </div>
    </div>
无法处理预期结果-->请求。访问被拒绝,只读


实际结果-->[]

请阅读并相应地编辑您的问题,您得到了什么错误堆栈跟踪?你的代码试用版在哪里?元素html结构是什么样子的?等重现/调试问题所需的东西,从现在开始,记住添加必要的细节,以便获得可能有用的响应。如果要成为一个模态对话框,您需要诱导WebDriverWait。非常感谢它的工作
@FindBy(xpath="//*[@id='informationModal']//h2")
WebElement certMessage;
String message = certMessage.getText();
System.out.println("Message -->"+ message);