尝试使用以下方法自动下拉,但无法选择下拉值。
方法1:
const comboOption = Selector("mat-option").child("span").withExactText("Hello");
await t.click(comboOption);
方法二:
ClientFunction(() => {
document.getElementsByClassName('mat-option-text')[0].innerText = 'Hello';
document.getElementsByClassName('mat-option-text')[0].click();
return "Hello";});
mat-option标记不在mat-select内。它在mat-select之外,在div标记内。有没有其他方法来实现自动mat-option?
发布于 2021-11-23 01:01:51
感谢您的代码片段。
据我所知,您正在尝试单击另一个选择元素中的选项元素。我创建了一个简单的测试,它应该执行您描述的步骤:
import { Selector } from 'testcafe';
fixture`Getting Started`
.page`http://devexpress.github.io/testcafe/example`;
const selectElement = Selector('#preferred-interface');
const optionElement = selectElement.find('option');
test('My first test', async t => {
await t
.click(selectElement)
.click(optionElement.withText('Both'))
.expect(selectElement.value).eql('Both');
});
如果我误解了你的问题,你能分享一个你的.html的简单例子,以及你想要在测试中做什么和你期望的结果的详细描述吗?
https://stackoverflow.com/questions/70063711
复制