Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >testcafe中的Automating mat-option

testcafe中的Automating mat-option
EN

Stack Overflow用户
提问于 2021-11-22 01:44:19
回答 1查看 31关注 0票数 0

尝试使用以下方法自动下拉,但无法选择下拉值。

方法1:

代码语言:javascript
运行
AI代码解释
复制
const comboOption = Selector("mat-option").child("span").withExactText("Hello");
await t.click(comboOption);

方法二:

代码语言:javascript
运行
AI代码解释
复制
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?

EN

回答 1

Stack Overflow用户

发布于 2021-11-23 01:01:51

感谢您的代码片段。

据我所知,您正在尝试单击另一个选择元素中的选项元素。我创建了一个简单的测试,它应该执行您描述的步骤:

代码语言:javascript
运行
AI代码解释
复制
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的简单例子,以及你想要在测试中做什么和你期望的结果的详细描述吗?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70063711

复制
相关文章

相似问题

添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档