首页 > 解决方案 > 在量角器中选择单选按钮

问题描述

我得到以下代码,如下所示:

<div class="inner">
    <h1> SOme text here</h1>
    <app-secondpart>
        <div class="class2">
            <label> some label</label>
            <label> 
                <input id="yes" type="radio">
                "Yes"
            </label>
            <label> 
                <input id="no" type="radio">
                "No"
            </label>
        </div>
    </app-secondpart>
</div>

我希望使用此代码“element(by.id("yes")).click();”选择/单击“是” 但是在运行应用程序时,我收到此错误“失败:元素不可交互”。

顺便说一下,我是 Protractor 的新手。

标签: protractor

解决方案


试试下面的js点击按钮。

export async function jsClickButton() {

    try {
        let btn = element(By.id('yes'));
        await browser.executeScript('arguments[0].click()', btn).then(async() => {
            console.log('Btn has been clicked.');
        });
    } catch (error) {
        console.log('Button is not clickable due ' + error);
    }
}
  • 第二种解决方案是单击标签元素。

推荐阅读