2016-12-22 12 views
1

私はNightwatch-cucumberとpageオブジェクトを使用しています。私はXpath経由で自分の要素を見つけるためにロケータを取得するのに苦労しています。NightwatchJS +キュウリはxPath経由で見つけることができません

<div class="portal-layout-section" style="width: 1215px; height: 730px; overflow: hidden;"> 
<div class="item bordered portal-hoverable" style="width: 243px; height: 365px; background-image: url(http://path/to/img/Ironman.jpeg;);"></div> 
<div class="item bordered portal-hoverable" style="width: 243px; height: 365px; background-image: url(http://path/to/img/FriendsWithBenefits.jpeg);"></div> 
<div class="item bordered portal-hoverable" style="width: 243px; height: 365px; background-image: url(http://path/to/img/Inception.jpeg);"></div></div> 
</div> 

私のステップは、このコードが含まれます:

要素は、次のようになります

var anonbrowse = this.page.anonbrowse(); 
anonbrowse 
    .waitForElementVisible('@cover_images_ironman',5000) 
    .click('@cover_images_ironman') 

をとPageオブジェクトは、次のようになります

module.exports = { 
elements: { 
    cover_images_ironman: { 
     selector : '//div[contains(@style,"http://path/to/img/Ironman.jpeg")]', 
     locateStrategy: "xpath"   

    }, 
} 
} 

私はタイムアウトエラーがない得続けますどのくらい私が待つままにしておきますか:

Timed out while waiting for element <//div[contains(@style,"http://path/to/img//Ironman.jpeg")]> to be present for 5000 milliseconds. - Expected "visible" but got: "not found" 
    at Object.<anonymous> (c:\nightwatxh\features\step_definitions\anonbrowse_steps.js:21:3) 
    at next (native) 
    at next (native) 

誰でも私がここで間違っていることを知りましたか?このような

+0

が//div[contains(@style,"Ironman.jpeg'にそれを簡素化してい '' または "" でどこかmisatkeを作ることができます) ] '何か違いはありますか?ありがとう。 – alecxe

+0

ありがとう、ちょうどそれを試み、まだ運がない。私はクロムプラグイン 'xpathヘルパー'で使用しているxpathを試してきました。右の要素を強調表示していますので、xpathが正しいことが分かります。 – spidee76

答えて

0

トライロケータ:

selector: '//div[contains(@style, "background-image: url(http://path/to/img//Ironman.jpeg))"]' 

iが "

+0

ありがとうございます、はい、私はアサーションを行ったようにnightwatchjsは要素を識別することができますが、それはそれをクリックすることはできません運がないが、それを試みたが、このDivがReactコンポーネントであるかどうかはわかりません。 – spidee76

+0

このような '.item.bordered.portal-hoverable:nth-​​child(1)'のようなCSSセレクタを試してみるとうまくいくはずです。要素に問題があるのか​​、夜間だけであるのかを知ります。 – Hikaryu

+0

お試しいただきありがとうございます、まだ運がない。このアサートは、次のように動作します。 '.expect.element( '@ cover_images_ironman')。to.have.css( '背景画像')。 'しかし、私がクリックすると、まだ動作していない:' .click( '@ cover_images_ironman') ' – spidee76

関連する問題