javascript - Cypress: How to get Href attribute value, redirect and match the URL with value
问题描述
- Please open the image HTML
I want to get the value (URL) of the first href for this class (.grid-item) then navigate to the respective href link and verify the value (URL) with the current page's URL.
How can I achieve that using Cypress?
Code:
selectStackup = () => {
cy.get(".grid-item")
.eq(1)
.invoke("attr", "href")
.then(href => {
cy.visit(href);
});
};
Error: - CypressError: cy.visit() must be called with a URL or an options object containing a URL as its 1st argument
解决方案
baseUrl
只需添加from cypress.json
OR的前缀yourUrl.com
以及href
and 就可以了。
cy.visit(`yourUrlOrBaseUrl.com${href}`);
推荐阅读
- c# - 在 C# winform 解决方案中使用线程但它没有中止
- html - 将测试对齐到导航栏的中间
- javascript - 如何访问 js 文件 VUEX 中的状态
- c++ - 错误:“double()”和“double()”类型的无效操作数到二进制“operator+”
- ruby - Ruby:需要与包含/扩展:在另一个模块中使用模块,但不向用户公开
- google-sheets - Google 表格:带有日期字符串的查询函数(源和返回格式相同)
- ebay-api - 未收到 eBay 通知
- html - 如何以响应方式将我的图像定位在标题的最后一行?
- javascript - 如何将javascript值传递给viewbag值
- sql-server - 如何从 TSQL 或 Power Query 中的先前行值生成结果