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

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

问题描述

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

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 - 隐藏选择和锚点 [重复]

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

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