在量角器端到端测试中单击隐藏元素的一种方法 [英] A way of clicking on hidden elements in protractor end to end tests

查看:15
本文介绍了在量角器端到端测试中单击隐藏元素的一种方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法点击子菜单中的隐藏值.我希望能够做类似的事情

Is there a way to click on a hidden value in a sub menu. I would like to be able to do something like

driver.findElement(protractor.By.xpath('/html/body/div/div/a')).mouseover.then(function() {
    ptor.findElement(protractor.By.className('name').getText().then(function(result) {
        expect(result).toBe('Me');
    });
});

当菜单项不可见时,或者我们目前受限于此.如果这不可能,目前是否有解决此问题的方法.

when the menu item is not visible, or are we limited with this at the moment. If this is not possible is there a way around this issue at present.

推荐答案

好吧,经过漫长而痛苦的搜索,试图找到这个问题的答案,我终于找到了答案,试图回答一个不同的问题.

ok so after a long and painful search trying to find an answer to this question I finally came across the answer trying to answer a different question.

我发现的大多数文档都解释说,我们必须以 WebElement 的形式使用 Actions,然后将其转换为 Javascript,并通过单击操作将数组形式的脚本元素传递给它.

Most of the documentation I found explain that we must use Actions in the form of a WebElement and then cast that to Javascript and pass it a script element in the form of an array with the click action.

同样的种类也在这里,但有一些修改.

Well the same kinds goes here but with a few modifications.

describe('', function() {
    var ptor = protractor.getInstance();
    var driver = ptor.driver;

    it('', function() {
        var hiddenElement = driver.findElement(protractor.By.yourchosenlocator(''));
        driver.executeScript("arguments[0].click()", hiddenElement).then(function() {
            expect(whatever).toMatch(whatever);
        });
    }, 30000);
});

如您所见,没有使用 webelement,也不需要强制转换.

as you can see there is no use of webelement and no cast required.

以下是帮助我寻找答案的资源

Here are the sources that helped me in my search for answers

你好吗单击使用 Selenium Webdriver 隐藏的元素?

SELENIUM WEBDRIVER – 如何点击隐藏的链接或菜单

Selenium WebDriver - 隐藏选择和锚点[重复]

这篇关于在量角器端到端测试中单击隐藏元素的一种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆