Scala Selenium webdriver无法单击使用XPath找到的元素

时间:2015-07-06 04:10:37

标签: scala selenium xpath selenium-webdriver

我写了这个简单的片段来点击一个菜单项,这个菜单项没有类或id,所以我必须使用属性找到该元素但是我得到这个元素不可点击的错误。

Scala代码

val s =  find(xpath("//tr[@aria-label='Show By ']")).get.underlying
click on s

错误

[[ChromeDriver: chrome on XP (bf45b57213899780871d25030c5838d7)] -> xpath: //tr[@aria-label='Show By ']]
←[31m  The code passed to eventually never returned normally. Attempted 16 times over 20.156217392000002 seconds. Last failure message: unknown error:
 Element is not clickable at point (844, 903). Other element would receive the click: <td class="dijitReset dijitMenuArrowCell" role="presentation">..
.</td>←[0m

HTML代码

<tr class="dijitReset dijitMenuItem" data-dojo-attach-point="focusNode" role="menuitem" tabindex="-1" id="dijit_PopupMenuItem_1" aria-label="Show By " widgetid="dijit_PopupMenuItem_1" aria-haspopup="true" style="-webkit-user-select: none;">
<td class="dijitReset dijitMenuItemIconCell" role="presentation">
    <span role="presentation" class="dijitInline dijitIcon dijitMenuItemIcon" data-dojo-attach-point="iconNode"></span>
</td>
<td class="dijitReset dijitMenuItemLabel" colspan="2" data-dojo-attach-point="containerNode,textDirNode" id="dijit_PopupMenuItem_1_text">Show By</td>
<td class="dijitReset dijitMenuItemAccelKey" style="display: none" data-dojo-attach-point="accelKeyNode" id="dijit_PopupMenuItem_1_accel"></td>
<td class="dijitReset dijitMenuArrowCell" role="presentation">
    <span data-dojo-attach-point="arrowWrapper">
        <span class="dijitInline dijitIcon dijitMenuExpand"></span>
        <span class="dijitMenuExpandA11y">+</span>
    </span>
</td>

1 个答案:

答案 0 :(得分:0)

问题是您尝试单击的元素正被另一个(可能是不可见的)元素覆盖。

有不同的方法来处理这个问题,但最简单的方法是只使用javascript点击元素。

driver.executeScript("arguments[0].click();", element);

是如何在java中完成的。我不知道scala中的正确语法是什么。