首页 > 解决方案 > 自动将文本输入到以角度定义可编辑字段的字段中,我的测试框架是 selenium webdriverio

问题描述

我正在尝试在表单的字段中输入文本。该字段上的操作以角度定义,我无法找到可编辑的对象。. 这是我的代码片段:

**Scenario**:
When I enter "xyz" into the "Headline" field
// Entering strings
When('I enter( the) {string} into the {string} field', enterText);
**selection**
/**
 * Enters specific text into an element
 * @param {string} text The text to enter
 * @param {string} field The field key for an element
 * @returns {Promise<WebElement|Error>} The obtained element as a promise
 */
export async function enterText(text, field) {
  console.log('enter text 1');
  const element = getSelector(field);
  console.log(element);
  await World.browser.setValue(element, text);

要输入文本的代码是用角度编写的,并且正在输入文本

标签不在标签中

我尝试使用 css 作为选择器 div > storyline-editor > cue-storyline > div > cue-story-element-editor-container > mouse-handler > ng-transclude > div > cue-story-element-editor > cue-text-story-element-editor > mouse-handler > ng-transclude > cue-rte > div > div > p

如果我在 selenium IDE 中使用上述选择器并运行代码,它可以正常工作,但它不适用于我的框架

1)检查新文章页面元素14 我在“标题”字段中输入“测试标题”: [chrome #0-0] unknown error: cannot focus element

标签: seleniumautomated-testscucumberwebdriver-io

解决方案


当您尝试将值设置为不是输入的元素时,您将看到 Failed: unknown error: cannot focus element 错误。

您需要先设置焦点或单击元素,然后再为其设置值。

export async function enterText(text, field) {
console.log('enter text 1');
const element = getSelector(field);
console.log(element);
await element.click()
await World.browser.setValue(element, text);

如果这不起作用,请使用执行 javascript 方法。


推荐阅读