我有一個奇怪的問題,在屏幕抓取與spookyjs/capserjs。CasperJS/SpookyJS css選擇器是存在和不存在
我想從以下網站獲取信息:'https://www.rwe-smarthome.de/is-bin/INTERSHOP.enfinity/WFS/RWEEffizienz-SmartHome-Site/de_DE/-/EUR/ViewApplication-DisplayWelcomePage'。
由於該網站包含多個產品頁面,我還想打開其他網站。
通常你可以使用
this.click(selector, function() {});
實現這一目標。
由於一些奇怪的原因,這裏不起作用。
請看看下面的代碼:
var selector1 = "div#workingTemplate div:first-of-type ul.linkList li:nth-child(2) a";
spooky.waitUntilVisible(selector1);
spooky.thenClick(selector1);
spooky.wait(500);
spooky.then(function() {
this.capture("RWETest-02.jpg");
});
我收到一個錯誤
CasperError: Cannot dispatch mousedown event on nonexistent selector: div#workingTemplate div:first-of-type ul.linkList li:nth-child(2) a
這很奇怪,因爲如果選擇/ DOM對象不存在,它應該會失敗在waitUntilVisible()
。
而且當我嘗試檢查,如果選擇存在,答案似乎是肯定的,因爲我也得到與不存在選擇的錯誤:
代碼:
spooky.then([{sel: selector1},function() {
if(this.exists(sel)) {
this.click(sel);
this.wait(500);
this.then(function() {
this.capture("RWETest-02.jpg");
});
}
else {
this.emit("logMessage", "Selector does not exists...");
}
}]);
錯誤:
CasperError: Cannot dispatch mousedown event on nonexistent selector: div#workingTemplate div:first-of-type ul.linkList li:nth-child(2) a
因爲SpookyJS我使用PhantomJS 1.9.7和CasperJS 1.1.0-beta3。
有沒有人有這方面的想法?
太好了,非常感謝你!對於任何與Webstorm和此解決方案相處的人來說,selectXPath必須放在一行中,否則會出錯。 – solick