单击div元素

时间:2018-10-18 16:02:02

标签: javascript html selenium selenium-webdriver protractor

我试图用量角器单击div元素,但这给我一个错误,提示“元素不可交互”。这是一个菜单,当您单击div之一时,应该会弹出另一个菜单。

    <div class="col">

        <div class="games">

                <div class="game" rel="board">
                    Chess
                </div>

                <div class="game" rel="sports">
                    Basketball
                </div>

                <div class="game" rel="active">
                    Exercise
                </div>

        </div>

    </div>

我尝试过的是

    element.all(by.cssContainingText('.game','Exercise')).click();
    element(by.cssContainingText('.game','Chess')).click();

2 个答案:

答案 0 :(得分:0)

JS点击

export async function jsClickButton(button: ElementFinder) {

    try {
        return await browser.executeScript('arguments[0].click()', button).then(async() => {
            console.log('Element has been clicked.');
        });
    } catch (error) {
        console.log('Element could not be clicked', error);
    }
}

答案 1 :(得分:0)

element.all(by.cssContainingText('.game','Exercise')).click();
browser.wait(ExpectedCondition.elementToBeClickable(element(by.cssContainingText('.game','Chess')),60000,'Wait for the element to become clickable'));
element(by.cssContainingText('.game','Chess')).click();

如果这样做无济于事,请先尝试添加browser.sleep(),然后再尝试访问该元素。