【发布时间】:2017-08-12 16:38:02
【问题描述】:
我正在与 Selenium 作斗争。
基本上我想点击以下元素来切换元素:
<div class="btn-group pull-right">
<a class=" mr-2" aria-expanded="false" aria-haspopup="true" data-toggle="dropdown-ddd" href="javascript:void(0)" onclick="$(this).closest('.btn-group').toggleClass('open');"
<svg class="">
<use xlink:href="resources/icons/settings.svg#Layer_1" xmlns:xlink="http://www.w3.org/1999/xlink">
</svg>
</a>
它变为:
<div class="btn-group pull-right open”>
<a class=" mr-2" aria-expanded="false" aria-haspopup="true" data-toggle="dropdown-ddd" href="javascript:void(0)" onclick="$(this).closest('.btn-group').toggleClass('open');">
<a class=" mr-2" aria-expanded="false" aria-haspopup="true" data-toggle="dropdown-ddd" href="javascript:void(0)" onclick="$(this).closest('.btn-group').toggleClass('open');">
<svg class="">
<use xlink:href="resources/icons/settings.svg#Layer_1" xmlns:xlink="http://www.w3.org/1999/xlink">
</svg>
</a>
我写的点击这个元素的方法:
WebElement dropDown = driver.findElement(By.xpath("//div[@class='btn-group.pull-right’]”));
dropDown.click();
但是,我遇到了一个异常:
没有这样的元素:无法找到元素:{"method":"xpath","selector":"//div[@class='btn-group.pull-right']"}
关于我为什么会收到此异常的任何建议?
【问题讨论】:
-
分享网站链接或html源代码
-
//div[contains(@class, 'btn-group') and contains(@class, 'pull-right')]? -
如果您尝试单击由
findElement(By.xpath("//div[@class='btn-group.pull-right’]”));返回的节点,只需在btn-group.pull-right之后将’更改为'即可。
标签: selenium