从非按钮元素触发单击

时间:2013-04-05 16:43:42

标签: c# javascript awesomium

您好在WPF / C#编程并使用awesomium WebControl

我想点击这个:

<li class="playlist-item-favorite" data-title="Ulubione" data-is-private="False">
      <a href="javascript: void(0);">
        <span class="playlist-title">
          Ulubione

          <span class="playlist-video-count-container">
            (<span class="playlist-video-count">1</span>)
          </span>
        </span>

        <span class="playlist-public-private">
Publiczny
        </span>
      </a>
    </li>

我的代码C#:

 dynamic lists = (JSObject)Browser.ExecuteJavascriptWithResult("document.getElementsByClassName('playlist-item-favorite')");

            if (lists == null)
                return;

        length = lists.length;
        if (length == 0)
            return;

        using (lists)
        {
            using (JSObject obiekt = lists.Invoke("item", 0))
                obiekt.InvokeAsync("click");
        }
    }

我知道我找到了这个对象,当我得到属性时它没关系,但点击不适合它。

我展示了此对象的方法,并且没有像click或onclick这样的方法。 方法:

insertAdjacentHTML
insertAdjacentText
insertAdjacentElement
getAttribute
setAttribute
removeAttribute
getAttributeNode
getElementsByTagName
getAttributeNS
setAttributeNS
removeAttributeNS
getElementsByTagNameNS
getAttributeNodeNS
hasAttribute
hasAttributeNS
focus
blur
scrollIntoView
scrollIntoViewIfNeeded
scrollByLines
scrollByPages
getElementsByClassName
querySelector
querySelectorAll
webkitMatchesSelector
getClientRects
getBoundingClientRect
setAttributeNode
removeAttributeNode
setAttributeNodeNS
webkitRequestFullScreen
insertBefore
replaceChild
removeChild
appendChild
hasChildNodes
cloneNode
normalize
isSupported
hasAttributes
lookupPrefix
isDefaultNamespace
lookupNamespaceURI
addEventListener
removeEventListener
isSameNode
isEqualNode
compareDocumentPosition
contains
dispatchEvent

你能帮助我吗?

@Edit 我发现这是为javascript: Trigger a button click from a non-button element 但我不能在我的应用程序中使用它。

1 个答案:

答案 0 :(得分:0)

网页中随附的Javascript中会有一个绑定到<a>元素点击事件的函数 - 找到它是什么,然后直接调用它。如果有问题的函数引用了self对象,则需要获取对该函数的引用并在其上调用call方法,并将anchor元素作为第一个参数传递。

替代方案 - 您正在尝试做的事情 - 可能更复杂。锚元素实际上没有clicked()函数,而是需要manually create an event