【问题标题】:Trigger a click from a non-button element从非按钮元素触发点击
【发布时间】:2013-04-05 16:43:42
【问题描述】:

你好,我在 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

你能帮帮我吗?

@编辑 我为javascript找到了这个: Trigger a button click from a non-button element 但我不能在我的应用程序中使用它。

【问题讨论】:

  • 为什么这被标记为 WPF?它与 WPF 无关。

标签: c# javascript awesomium


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2011-09-16
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多