使用以下代碼,我正在嘗試測驗傳入值“My test”的反應輸入,但在螢屏上(和組件值中)僅出現最后一個“t”
this.useXpath()
.waitForElementVisible('@subsetDialogNameInput')
.clearValue('@subsetDialogNameInput')
.setValue('@subsetDialogNameInput', name)
.pause(500)
.expect.element('@subsetDialogNameInput').to.have.value.that.equals(name)
然后測驗輸出變為:
Expected element @subsetDialogNameInput <.//*[local-name()="input" and @id="Subset-name"]> to have value that equals: "My test" - expected "equals 'My test'" but got: "t"
我在版本 100.0.0 上運行 chromedriver
編輯:根據要求為輸入欄位添加 jsx
import { TextField as MuiTextField } from '@mui/material';
import clsx from 'clsx';
import type { ChangeEvent } from 'react';
import { memo } from 'react';
import { formStyle } from '@/style';
import { asteriskStyle, controlStyle, inputReadOnlyStyle, inputStyle, labelReadOnlyStyle, labelStyle, nativeInputStyle } from './style';
interface Props {
readonly borderless: boolean;
readonly className: string | undefined;
readonly dark: boolean;
readonly id: string;
readonly label: string | undefined;
readonly onChange: (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
readonly readOnly: boolean;
readonly required: boolean;
readonly type: 'text' | 'number';
readonly value: string;
readonly max?: number | undefined;
readonly min?: number | undefined;
}
const TextField = ({ borderless, className, dark, onChange, id, label, max, min, readOnly, required, type, value }: Props) => (
<MuiTextField
autoComplete="off"
fullWidth
id={id}
InputLabelProps={{
classes: { root: clsx(labelStyle, dark ? formStyle.labelDark : formStyle.labelLight, readOnly && labelReadOnlyStyle), asterisk: asteriskStyle }
}}
inputProps={{ className: nativeInputStyle, max, min, tabIndex: readOnly ? -1 : 0 }}
InputProps={{
readOnly,
className: clsx(
inputStyle,
dark ? formStyle.inputDark : formStyle.inputLight,
borderless && formStyle.inputBorderless,
readOnly && inputReadOnlyStyle
)
}}
label={label}
onChange={onChange}
required={required}
type={type}
value={value}
variant="filled"
className={clsx(controlStyle, className)}
/>
);
export default memo(TextField);
uj5u.com熱心網友回復:
useState在 TextField 的父組件上添加一個鉤子,并在里面使用回呼函式setInputValue解決了這個問題。似乎在通過 selenium 函式鍵入時會創建某種競爭條件setValue,并且使用 setState 回呼解決了它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/461180.html
