英文:
CCS Selector for Cypress
问题
这是你要翻译的内容:
"When selecting a field which contains a drop-down list with two options, I was able to find the xpath, but I would like to know if there is another method that I can use for this case
these are the the two elements:
ESS
Admin
<div class="oxd-select-text-input" tabindex="0" data-v-5df604d8="">Admin</div>
<div class="oxd-select-text-input" tabindex="0" data-v-5df604d8="">ESS</div>
I need to get to that element
This is an xpath I tried but in cypress, but it doesn't work
//\*\[@id="app"\]/div\[1\]/div\[2\]/div\[2\]/div/div/form/div\[1\]/div/div\[1\]/div/div\[2\]/div/div/div\[1\]
英文:
When selecting a field which contains a drop-down list with two options, I was able to find the xpath, but I would like to know if there is another method that I can use for this case
these are the the two elements:
ESS
Admin
<div class="oxd-select-text-input" tabindex="0" data-v-5df604d8="">Admin</div>
<div class="oxd-select-text-input" tabindex="0" data-v-5df604d8="">ESS</div>
I need to get to that element
This is an xpath I tried but in cypress, but it doesn't work
//\*\[@id="app"\]/div\[1\]/div\[2\]/div\[2\]/div/div/form/div\[1\]/div/div\[1\]/div/div\[2\]/div/div/div\[1\]
答案1
得分: 3
以下是翻译好的内容:
我认为您想要通过内部文本选择元素,因为这些元素看起来相同。
类似于这样:
cy.get('div.oxd-select-text-input:contains("Admin")')
// 或
cy.get('div.oxd-select-text-input') // <- 这里有两个元素的列表
.contains('Admin')
//和
cy.get('div.oxd-select-text-input:contains("ES")')
// 或
cy.get('div.oxd-select-text-input') // <- 这里有两个元素的列表
.contains('ES')
第二种最好的方式是指定列表中的位置
cy.get('div.oxd-select-text-input') // <- 这里有两个元素的列表
.eq(0) // <- 获取第一个
// 或
cy.get('div.oxd-select-text-input') // <- 这里有两个元素的列表
.eq(1) // <- 获取第二个
英文:
I think you would want to select the element by text inside, since the elements look the same.
Something like this:
cy.get('div.oxd-select-text-input:contains("Admin")')
// or
cy.get('div.oxd-select-text-input') // <- here is a list of two elements
.contains('Admin')
//and
cy.get('div.oxd-select-text-input:contains("ES")')
// or
cy.get('div.oxd-select-text-input') // <- here is a list of two elements
.contains('ES')
Second best way is to specify the position in the list
cy.get('div.oxd-select-text-input') // <- here is a list of two elements
.eq(0) // <- take first one
//or
cy.get('div.oxd-select-text-input') // <- here is a list of two elements
.eq(1) // <- take second one
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论