1

I'm working on some Selenium/Robot Framework automated testing, and I need a way to automate locating div tags that are clickable.

The Click Element keyword does the trick if I give it a very specific CSS selector, but how can I algorithmically find an element that can be clicked? As long as there is a way to get the DOM node, I'm hoping to return a unique selector that I can use to call the Click Element keyword.

I understand that old versions of jQuery have $(element).data('events') that might be used to find click listeners, but it seems like an unreliable method. Moreover, the Chrome web inspector doesn't seem to recognize any click listeners for the divs that I'm looking at.

For completeness, here is an example of the HTML I'm working with:

<div id="contentarea" class="">
  <div id="contentwrapper" style="opacity: 1;">
    <div class="rap">
      <div id="twocol" class="clearfix margintop">
        <div class="leftcol scrollable addprogram">
          <a href="..." class="newgroup">
            <span class="addicon"></span>New Group
          </a>
        </div>
        <div class="rightcol clearfix">
          <ul class="subtabs rounded clearfix">
            <li data-tab="pending" class="selected">
              <a href="..." class="selected">Released</a>
            </li>
          </ul>
          <div class="clear"></div>
          <div id="program-grid" class="clearfix" style="">
            <div class="program groups" tabindex="0">
              <div class="programframe"></div>
              <div class="programinfo">
                <h1 class="prizeheight">Development</h1>
              </div>
              </div><div class="program groups" tabindex="0">
              <div class="programframe"></div>
              <div class="programinfo">
                <h1 class="prizeheight">Loss Prevention/Safety Group</h1>
              </div>
... 
...

<div class='program groups'> is a clickable element that I hope to identify programmatically.

For the record, the HTML is valid and so on. Minified Javascript somehow renders this source, and probably attaches the listeners.

Thanks!

4

1 回答 1

0

根据本网站,这可能是不可能的。

注册了哪些事件处理程序?

W3C 事件注册模型当前实现的一个问题是,您无法确定是否有任何事件处理程序已注册到元素。在传统模型中,您可以这样做:

alert(element.onclick) 并且您会看到注册到它的函数,或者如果没有注册则未定义。仅在其最近的 DOM Level 3 事件中,W3C 添加了一个 eventListenerList 来存储当前在元素上注册的事件处理程序列表。任何浏览器尚不支持此功能,它太新了。但是,问题已经解决。

幸运的是,如果您要删除的事件侦听器尚未添加到元素中,则 removeEventListener() 不会给出任何错误,因此当您有疑问时,您始终可以使用 removeEventListener()。

于 2013-09-13T20:29:41.040 回答