【问题标题】:Element Not Visible after Switching to NewWindow切换到 NewWindow 后元素不可见
【发布时间】:2016-05-19 04:20:39
【问题描述】:

切换到新窗口后,只有 'urlContains' 有效。

没有其他事情发生(点击也没有 elementVisible 或任何事情)

守夜人部分代码:

'Order Module' : function(browser) {
browser
    .useXpath()
    .waitForElementVisible("@OrderTab", 20000)
    .pause(5000)
    .click("@OrderTab")
    .pause(5000)
    .useCss()
    .waitForElementVisible("input[title = 'New']", 20000)
    .click("input[title = 'New']")
    .useXpath()
    .waitForElementVisible("@OrderTextBox']", 20000)
    .verify.urlContains('https://invoiceit-s.na30.visual.force.com/apex/createJobStep1?retURL=%2Fa0K%2Fo&save_new=1&sfdc.override=1')
    .setValue("@OrderTextBox", "Order Name")
    .pause(10000)
    .click("@LinkIconForNewWindow")
    .pause(10000)
    .window_handles(function(result) {
        this.verify.equal(result.value.length, 2, '2 windows should be open')
        var handle = result.value[1]
        this.switchWindow(handle)
        this.verify.urlContains('https://invoiceit-s.na30.visual.force.com/_ui/common/data/LookupPage?lkfm=j_id0%3AjobForm&lknm=j_id0%3AjobForm%3Apb%3Arender%3Aj_id38%3A0%3Aj_id39&lktp=001&lksrch=')
        this.useXpath()
        this.waitForElementVisible("@searchBox", 20000)
    })
    .pause(20000)
    .end() }

【问题讨论】:

    标签: node.js selenium-webdriver functional-testing nightwatch.js


    【解决方案1】:

    我不熟悉Xpath,你能发布元素块的屏幕打印吗?也许我可以帮助你

    PS:不要使用太多的 pause(),它会减慢你的测试程序,nightwatch 会每 500 毫秒检查一次元素。

    编辑1:问题可能是因为'@searchBox'元素,这是在您单击弹出按钮后浏览器的第一个选项卡中吗?如果是,应该是这样的:

    .window_handles(function(result) {
          var home = result.value[0], // your first tab
              handle = result.value[1]; // second tab
             this
                .switchWindow(handle)
                .verify.urlContains('https://invoiceit') 
                .useXpath() 
                .switchWindow(home) // you need to switch back to first tab , even you close the pop-up.
                .waitForElementVisible("@searchBox", 20000) 
        })
    

    PS:我在这篇文章中的回答可能会有所帮助。Loop is not working properly - nightwatch

    【讨论】:

    • 不是 xPath 错误。它也不适用于'waitForElementVisible('body',20000)'。正如 body 出现在每个 DOM 中一样。我错过了 switchWindow 方法中的任何内容吗?
    • Xpath 使您的代码难以阅读,例如,您可以将“.//*[@id='01r36000000RX00_Tab']/a”更改为“#Tab”或“ div[name=tab]'。我(可能是其他任何人)很难知道你的测试中的元素是什么意思。
    猜你喜欢
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-14
    • 2021-01-19
    • 2020-02-19
    相关资源
    最近更新 更多