0

嗨,我在 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找到了这个: 从非按钮元素触发按钮点击 但我不能在我的应用程序中使用它。

4

1 回答 1

0

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

另一种选择——你想要做的——可能更复杂。锚元素实际上没有clicked()功能,而是您需要手动创建一个事件

于 2013-04-05T17:47:15.003 回答