【问题标题】:Switch to another window in Cypress在 Cypress 中切换到另一个窗口
【发布时间】:2020-01-29 16:58:45
【问题描述】:

我想在按下按钮时切换到新窗口,并且新窗口具有动态 URL,我们如何处理。是否有任何解决方法。我搜索了很多文章

点击添加按钮

cy.get('a[href*="javascript:xxxSearch();"]').click()

打开一个新窗口

我想访问(在新窗口中搜索/添加元素,然后切换回上一个主窗口

【问题讨论】:

  • 我们需要有关此问题的更多详细信息。该按钮是否会打开一个新窗口并通向另一个页面?或者它是一个模态?你能创建a minimal, reproducible example吗?
  • 该网址是否在 cypress 中作为“新”标签打开?如果可能的话,你能分享一下html吗..
  • @ManuelAbascal 问题已更新
  • @soccerway 问题已更新

标签: cypress


【解决方案1】:

如果您可以共享该页面的完整 html,可能是个好主意。正如我从问题中了解到的那样,可能是抓住href,然后将href 的属性获取到const,然后访问该链接,如下所示。试一试,让我知道这是否适合你。

it('Open a new window',function(){
    cy.visit('some_url')
    //test code continues....

    cy.get('a[href="/some/link"]').then(($href)=>{
        const hrefLink = $href.attr('href');
        cy.visit(hrefLink);
        // rest of you test to grab the search button 
    })
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多