![](/img/trans.png)
[英]Hover over element changes element which is then included in hover over
[英]Hover over element with CasperJS
如何在元素上執行單擊事件,將其懸停在元素上后將變得可見。 以下是HTML代碼
<div class="jqtree-element jqtree_common">
<span class="jqtree-title jqtree_common" contenteditable="true">Notebook 1</span>
<span class="notebook-right">
<span class="notebook-date disappear" style="visibility: visible;">
<span class="notebook-commands-right">
<span class="notebook-commands appear-wrapper">
<span class="notebook-commands appear" style="display: none;">
<span class="fontawesome-button info">
<span class="fontawesome-button history">
<span class="fontawesome-button private">
<span class="fontawesome-button public" style="display: none;">
<span class="fontawesome-button remove">
<i class="icon-remove"></i>
</span>
</span>
</span>
</span>
</div>
要刪除我正在使用以下代碼的筆記本
casper.then(function(){
if(this.visible({type:'xpath', path:'/html/body/div[3]/div/div[1]/div[1]/div/div/div[1]/div[2]/div/div/ul/li[1]/ul/li[1]/ul/li[11]/div/span[2]/span[3]/span/span[5]/i'}))
{
this.click({type:'xpath', path:'/html/body/div[3]/div/div[1]/div[1]/div/div/div[1]/div[2]/div/div/ul/li[1]/ul/li[1]/ul/li[11]/div/span[2]/span[3]/span/span[5]/i'});
});
console.log('notebook '+ title +' deleted');
} else {
console.log('element not found');
}
});
在控制台中,它顯示“無法調度mousedown事件。”
CasperJS的鼠標模塊具有move()
函數。 它需要一個坐標或一個選擇器。 CasperJS將使用基礎的PhantomJS sendEvent()
函數創建本地事件。
casper.mouse.move(someCSSSelector);
要么
var x = require('casper').selectXPath;
...
casper.mouse.move(x(someXPathExpression));
如果此后頁面加載了一些內容,則可能需要在移動鼠標后稍等一下:
casper.mouse.move(someCSSSelector);
casper.waitUntilVisible(expectedElementSelector, function(){
this.click(expectedElementSelector);
});
幾乎所有功能都可以與XPath表達式以及CSS選擇器一起使用。
如果我沒看錯,我想你的意思是觸發點擊事件。 可以使用本機javascript完成,操作如下:
var note = document.getElementById('note'); note.onclick = function(){ alert('Someone click me'); } var evtClick = document.createEvent('Event'); evtClick.initEvent('click', true, true); note.onmouseover = function() { this.dispatchEvent(evtClick); };
<b id='note'>Hover me!</b> It will trigger click event.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.