CCS选择器用于Cypress

huangapple go评论69阅读模式
英文:

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(&#39;div.oxd-select-text-input:contains(&quot;Admin&quot;)&#39;)
// or
cy.get(&#39;div.oxd-select-text-input&#39;)    // &lt;- here is a list of two elements
  .contains(&#39;Admin&#39;)

//and

cy.get(&#39;div.oxd-select-text-input:contains(&quot;ES&quot;)&#39;)
// or
cy.get(&#39;div.oxd-select-text-input&#39;)    // &lt;- here is a list of two elements
  .contains(&#39;ES&#39;)

Second best way is to specify the position in the list

cy.get(&#39;div.oxd-select-text-input&#39;)    // &lt;- here is a list of two elements
  .eq(0)                               // &lt;- take first one
//or
cy.get(&#39;div.oxd-select-text-input&#39;)    // &lt;- here is a list of two elements  
  .eq(1)                               // &lt;- take second one 

huangapple
  • 本文由 发表于 2023年2月9日 02:38:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75390331.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定