testing - 如何像使用 Chrome 开发者控制台一样使用 querySelectorAll 选择正确的元素?

标签 testing automation salesforce cypress

我目前正在使用 cypress 来测试 salesforce,并且遇到了某种情况,我不知道将在机会中创建它的派对记录 ID。这意味着我必须找到一种解决方法来选择特定的聚会记录才能编辑文件。

如果我使用 Chrome 工具或在 cypress 中执行以下操作,我可以调用该元素,但它不会打开或单击任何内容:

       cy.document().then((doc) => {
                const edit = doc.querySelectorAll("a")[41]
                const click = doc.querySelectorAll("a")[42]
                edit.click()
                click.click()

            })

问题是 cypress 没有发出任何点击,我无法前进。有谁知道在这些情况下我们可以做什么?

这是向下箭头元素:

enter image description here

最佳答案

您可以使用eq()直接获取第二个下拉菜单并对其执行 click() 。

cy.get('svg[data-key="down"]')             // select all dropdowns
  .eq(1)                                   // select the second
  .click();

或者您可能需要定位 <use href...>元素,

cy.get('svg[data-key="down"]')             // select all dropdowns
  .eq(1)                                   // select the second
  .find('use')                             // since this element has the href
  .click();

关于testing - 如何像使用 Chrome 开发者控制台一样使用 querySelectorAll 选择正确的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67406513/

相关文章:

.spec 文件中无法识别 Angular 8+ tsconfig 路径别名

python - 在 Python 中拦截 subprocess.Popen 调用

reactjs - 导入图像会破坏 Jest 测试

javascript - 使用 sinonjs 进行假 Ajax 调用

java - Apex:map.Put() byVal 而不是 byRef?

javascript - 在浏览器中使用JS Pact时,如何创建pact文件?

macos - 使用高 CPU 时通知。通过 AppleScript 还是 Automator?

php - 用 Ansible 替换配置行

Java - 重构类似方法的代码

python-2.7 - 使用 python 导入 Salesforce 报告数据