NightwatchJS + Cucumber无法通过xPath找到

时间:2016-12-22 16:14:22

标签: xpath selenium-webdriver nightwatch.js cucumberjs

我正在使用Nightwatch-cucumber和页面对象,我正在努力让定位器通过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')

Pageobject看起来像这样:

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)

任何人都有任何想法我在这里做错了吗?

1 个答案:

答案 0 :(得分:0)

尝试这样的定位器:

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

我可以用“”或“

在某处做错事