如何使用 PhantomJS 和 GhostDriver 单击模式对话框的关闭按钮

How to click on a close button of a modal dialog with PhantomJS and GhostDriver

我正在尝试使用 Java、PhantomJS 和 GhostDriver 截取一些 Twitter 页面的屏幕截图,但我一直在获取带有模式对话框(注册模式或 cockies 模式)的屏幕截图。

有人可以告诉我如何找到这个关闭按钮并单击它吗?按钮上没有直接显示class或id,如图所示:

这里是 html:

<body class="three-col logged-in user-style-Nike ms-windows enhanced-mini-profile ProfilePage ProfilePage--withBlockedWarning supports-drag-and-drop" dir="ltr" data-fouc-class-names="swift-loading" style="background-position: 0% 46px;">
<div id="kb-shortcuts-msg" class="visuallyhidden">
<script id="swift_loading_indicator" nonce="ZLwCWCggSYkG1TzZ4188og==">
<div id="doc" class="route-profile">
<div class="topbar js-topbar">
<div id="page-outer">
<div id="page-container" class="AppContent">
<div class="BannersContainer BannersContainer--overlay">
<div class="Banner eu-cookie-notice">
<style>
<div class="flex-module">
<div class="banner-row">
    <span class="title">
    To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor Twitter Ads, measure their performance, and provide you with a better, faster, safer Twitter experience. By using our services, you agree to our
    <a href="https://support.twitter.com/articles/20170514">Cookie Use</a>
    .
    </span>
    <button type="button">
        <span class="icon close-medium">
            <span class="visuallyhidden">Close</span>
        </span>
    </button>
</div>
</div>
</div>

无法登录。

每个 DOM 元素都可以添加一个点击处理程序。有些元素已经自动添加了处理程序,例如 <a> 元素或表单内部的 <button>

因此,您只需单击 .eu-cookie-notice span.icon.close-medium 范围或其父级 .eu-cookie-notice .banner-row > button