java - 在 selenium 的活动窗口中未单击 X 图标
问题描述
以下代码不起作用:
List<WebElement> close=driver.findElements(By.xpath(".//a[@aria-label='Close' and @role='button' and @class='k-button k-bare k-button-icon k-window-action']"));
close.get(4).click();
HTML 代码:
<div class="k-window-titlebar k-header" style="margin-top: -28px;"
<span id="relatedNumberWindow_wnd_title"class="k-window-title" Related Numbers
</span>
<div class="k-window-actions" >
<a class="k-button k-bare k-button-icon k-window-action" role="button" aria-label="Close" </a>
</div>
</div>
我想点击 X 图标(在上面没有写代码的最小化和最大化中,否则它会太长)来关闭我的活动窗口。
我怎样才能完成这项任务?
解决方案
要单击X图标,您可以使用以下任一解决方案:
cssSelector
:driver.findElement(By.cssSelector("div.k-window-titlebar.k-header a.k-button.k-bare.k-button-icon.k-window-action[aria-label='Close']")).click();
xpath
:driver.findElements(By.xpath("//div[@class='k-window-titlebar k-header']//a[@class='k-button k-bare k-button-icon k-window-action' and @aria-label='Close']")).click();
推荐阅读
- vb.net - 用鼠标移动后,PictureBox 会在 Form1 上留下重影吗?
- discord - 在频道上获取第一条消息
- php - 复式会计报告
- javascript - Why can't I refer to the inherited method from JavaScript prototype within method
- asp.net-core - .net core modelstate 使用带有 guid 的选择列表无效
- arrays - 使用外部 JSON 文件而不是 .TS 文件进行预输入
- javascript - 数组不推送预期的元素
- python - Simple Client - Server scripts don't work, Timeout error 10060 when attempting to connect
- r - 稳健回归中的 MM 估计
- amazon-ec2 - 容器如何在 AWS EC2 虚拟化上运行?