【发布时间】:2019-11-18 11:45:41
【问题描述】:
尊敬的 stackoverflow 成员, 我在 cypress.io 中测试我们的网页时遇到问题 我正在使用 jquery 中的 $().each() 函数进行迭代,并尝试在表格行中查找特定元素并尝试使其“突出显示或'选中'”。 疯狂的是当我尝试条件部分时:
let number = $("#idOfSomething").text(); // Here i store the text from a dynamic label
// which get its value from db
if( Cypress.$(this).find('td:eq(1):contains("' + number+ '")').length > 0 ){
// nothing found
}
-------------或------------------
else if (Cypress.$(this).find('td:eq(1)').text() == number ){
// nothing found
}
但是如果我尝试将值放在条件部分 HARD CODED 中,那么它会找到它
if (Cypress.$(this).find('td:eq(1)').text() == "xy123" ){
cy.log(number) // prints "xy123"
}
为什么会这样???
另一件事是,当我尝试使用与上面相同的函数遍历同一张表时 并且表格比一页长,然后我使用此功能向下滚动到表格底部:
cy.get("#myTable").scrollTo("bottomLeft");
当它遍历每个元素时, 如果在函数向下滚动之前它最初不在屏幕上,它不会找到该元素。 我的意思是,如果我在条件部分输入像“1”这样的数字:
if(Cypress.$(this).find('td:eq(1)').text() == 1 ){
// here it finds the entry 1 in the table, because it is at the first page directly,
// 但是让我们说类型 50 而不是 1 --> 现在 50 不在屏幕上。 // cypress 向下滚动...我在屏幕上看到了数字 50,但 CYPRESS 看不到它。 }
我还尝试单击表格标题,以便数字得到 DESC ...所以一开始是 50 ...也不起作用。 我还尝试通过偏移 xy.. 向下滚动到底部。
【问题讨论】: