NightwatchJS+;Cucumber无法通过xPath定位

NightwatchJS+;Cucumber无法通过xPath定位,xpath,selenium-webdriver,nightwatch.js,cucumberjs,Xpath,Selenium Webdriver,Nightwatch.js,Cucumberjs,我正在使用Nightwatch cucumber和page对象,我正在努力让定位器通过Xpath找到我的元素 元素如下所示: <div class="portal-layout-section" style="width: 1215px; height: 730px; overflow: hidden;"> <div class="item bordered portal-hoverable" style="width: 243px; height: 365px; backgr

我正在使用Nightwatch cucumber和page对象,我正在努力让定位器通过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>
module.exports = {
elements: {
     cover_images_ironman: {
       selector : '//div[contains(@style,"http://path/to/img/Ironman.jpeg")]',
       locateStrategy: "xpath"          

    },
 }
}
selector: '//div[contains(@style, "background-image: url(http://path/to/img//Ironman.jpeg))"]'
页面对象如下所示:

<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>
module.exports = {
elements: {
     cover_images_ironman: {
       selector : '//div[contains(@style,"http://path/to/img/Ironman.jpeg")]',
       locateStrategy: "xpath"          

    },
 }
}
selector: '//div[contains(@style, "background-image: url(http://path/to/img//Ironman.jpeg))"]'
无论等待多长时间,我都会收到超时错误:

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)
等待元素出现5000毫秒时超时。-应为“可见”,但得到“未找到”
反对。(c:\nightwatxh\features\step\u definitions\anonbrowse\u steps.js:21:3)
在下一个(本地)
在下一个(本地)
有人知道我做错了什么吗?

试试这样的定位器:

<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>
module.exports = {
elements: {
     cover_images_ironman: {
       selector : '//div[contains(@style,"http://path/to/img/Ironman.jpeg")]',
       locateStrategy: "xpath"          

    },
 }
}
selector: '//div[contains(@style, "background-image: url(http://path/to/img//Ironman.jpeg))"]'
我可以在某处用“”或“”制作misatke

试试这样的定位器:

<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>
module.exports = {
elements: {
     cover_images_ironman: {
       selector : '//div[contains(@style,"http://path/to/img/Ironman.jpeg")]',
       locateStrategy: "xpath"          

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

我可能会在某处使用“”或“”

将其简化为
//div[contains(@style,“Ironman.jpeg”)]
有什么区别吗?谢谢,谢谢,我试过了,但还是不走运。我试过在chrome插件“xpath helper”中使用的xpath,它突出显示了正确的元素,因此我知道xpath是正确的。将其简化为
//div[contains(@style,“Ironman.jpeg”)]
会有什么不同吗?谢谢,谢谢,我试过了,但还是不走运。我试过在chrome插件“xpath helper”中使用的xpath,它突出显示了正确的元素,因此我知道xpath是正确的。谢谢,是的,我试过了,但运气不好,nightwatchjs能够识别元素,因为我已经做了断言,但它无法单击它。我不确定这是否与这个Div是一个React组件有关。请尝试像这样的css选择器
。item.bordered.portal hoverable:nth child(1)
,它应该可以工作,我们将知道元素或只是NightWatch是否有问题谢谢您的尝试,但仍然没有运气。此断言有效:
.expect.element('@cover\u images\u ironman')。to.have.css('background-image')。which.contains('url('http://Ironman.jpeg")');但当我单击时,它仍然不起作用:
。单击(“@cover\u images\u ironman”)
谢谢,是的,我尝试过,但运气不好,nightwatchjs能够识别元素,因为我已经做了断言,但它无法单击它。我不确定这是否与这个Div是一个React组件有关。请尝试像这样的css选择器
。item.bordered.portal hoverable:nth child(1)
,它应该可以工作,我们将知道元素或只是NightWatch是否有问题谢谢您的尝试,但仍然没有运气。此断言有效:
.expect.element('@cover\u images\u ironman')。to.have.css('background-image')。which.contains('url('http://Ironman.jpeg")');但当我单击时,它仍然不起作用:
。单击(“@cover\u images\u ironman”)