简体   繁体   English

使用 CSS 选择器时 WebdriverIO 行为与 Chrome devtools 控制台不同

[英]WebdriverIO behaviour different from Chrome devtools console while using CSS selectors

Below is the code snippet of html I'm trying to access via WebdriverIO下面是我试图通过 WebdriverIO 访问的 html 的代码片段

<div lightning-basecombobox_basecombobox="" class="slds-combobox__form-element slds-input-has-icon slds-input-has-icon_right" role="none">
<button lightning-basecombobox_basecombobox="" class="slds-combobox__input slds-input_faux" id="combobox-button-105" type="button" aria-expanded="false" aria-haspopup="listbox" name="payFrequency" role="combobox" data-value="" aria-label="Pay Frequency, --Select Pay Frequency--" aria-required="true" aria-controls="dropdown-element-105" aria-describedby="help-text-104"><span lightning-basecombobox_basecombobox="" class="slds-truncate">--Select Pay Frequency--</span></button>
<div lightning-basecombobox_basecombobox="" class="slds-input__icon-group slds-input__icon-group_right"><lightning-icon lightning-basecombobox_basecombobox="" class="slds-input__icon slds-input__icon_right slds-icon-utility-down slds-icon_container">
<lightning-primitive-icon><svg class="slds-icon slds-icon-text-default slds-icon_xx-small" focusable="false" data-key="down" aria-hidden="true" viewBox="0 0 52 52"><g><path d="M8.3 14h35.4c1 0 1.7 1.3.9 2.2L27.3 37.4c-.6.8-1.9.8-2.5 0L7.3 16.2c-.7-.9-.1-2.2 1-2.2z"></path></g></svg></lightning-primitive-icon></lightning-icon></div></div>

It is a combobox drop-down with a list a values to select.它是一个 combobox 下拉列表,其中列出了 select 的值。 Perform a click and select one of the option is the intended outcome.执行单击和 select 选项之一是预期的结果。 Only the xpath selector works with wdio which is,只有 xpath 选择器适用于 wdio,即,

$(`//button[@name="payFrequency"]`)

And none of the below CSS Selectors work,以下 CSS 选择器均不起作用,

$(`.slds-combobox__input.slds-input_faux`)
$(`button[name="payFrequency"]`)

The above selector works well in Chrome Devtools console and I request a clarity why it doesn't work with wdio?上述选择器在 Chrome Devtools 控制台中运行良好,我要求澄清为什么它不适用于 wdio?

All the different selectors you are sharing with us here should work in wdio .您在此处与我们共享的所有不同选择器都应该在wdio中工作。

This is the documentation of all the different selectors supported by wdio if you want to take a deeper look:如果您想更深入地了解,这是 wdio 支持的所有不同选择器的文档:

https://webdriver.io/docs/selectors https://webdriver.io/docs/selectors

So, I would bet your issue is more related with the behavior of your site more than a problem with wdio selectors.所以,我敢打赌,您的问题与您网站的行为有关,而不是 wdio 选择器的问题。

If you are struggling with some selectors I would try adding a wait like this to know what exactly is happening:如果您在使用某些选择器时遇到困难,我会尝试添加这样的等待以了解到底发生了什么:

https://webdriver.io/docs/api/element/waitForDisplayed https://webdriver.io/docs/api/element/waitForDisplayed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM