我不能用Nightwatch

时间:2016-05-11 06:45:17

标签: selenium nightwatch.js

我找不到任何地方如何点击模态按钮。困难的是,这个网站上的所有模态按钮都具有相同的ID,所以当我尝试简单的click()命令时,它只适用于网站的第一个模态。

修改

其实我的不好。我无法点击模态按钮。

编辑2
我有两个页面,两个都出现相同的模态。我的问题是当我尝试在第二页中按下这些按钮时。似乎它只对拳头模态做出反应。

<body class="bg ng-scope" ng-app="app">
<div class="ng-scope" autoscroll="true" ui-view="" style="">
<div class="ng-scope" src="'/js/layout/navbar.html'" ng-include="" style="">
<div id="searchContainer" class="container ng-scope">
<div id="resultsContainer" class="container ng-scope ng-hide" ng-show="vm.isAvailable"> </div>
<div class="ng-scope" src="'/js/layout/modals.html'" ng-include="" style="">
<script id="myModalContent.html" class="ng-scope" type="text/ng-template">
<div class="modal fade children-policy-modal ng-scope">
<div class="modal fade articles-modal ng-scope">
<div class="modal fade booking-code-modal ng-scope" style="display: none;">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<form class="ng-pristine ng-invalid ng-invalid-required" role="form" name="vm.bookingCodeForm">
<div class="modal-header">
<div class="modal-body">
<div class="modal-footer">
<button class="btn btn-info btn-sm ng-binding" ng-click="vm.checkBookingCode()" type="submit">BUTTON 1</button>
<button class="btn btn-default ng-binding" data-dismiss="modal" type="button">BUTTON2</button>

编辑3 我使用了以下代码

.click('a[data-target=".voucher-code-modal"]')
      .waitForElementVisible('button[class="btn btn-default ng-binding"]', 5000)
      .click('button[class="btn btn-default ng-binding"]')

我收到以下消息

  

警告:waitForElement找到9个选择按钮元素[class =“btn   btn-default ng-binding“]'}。只会检查第一个。

然后我的时间会超时。

2 个答案:

答案 0 :(得分:0)

所以你的xpath应该是这样的:.//div[@id='your id' and contains(@style,'display: block')]这只会给那些在点击时出现的模态...也确保上面xpath的结果数应该是1 ..请注意上面的xpath不是经过尝试和测试,但这些方面的内容应该给出答案。

答案 1 :(得分:0)

我使用以下内容选择模态窗口中的文本区域

'md-dialog[aria-label="Url Document ..."] textarea[name="description"]'

这使我的setvalue代码看起来像

.setValue('md-dialog[aria-label="Url Document ..."] textarea[name="description"]', 'random string')

不是最好的代码行,但是Page Objects可以让你整理它。

从我在您的代码段中可以解决的问题来看,您需要类似

的内容
.click(form[name='vm.bookingCodeForm'] button[type='submit'])