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

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

问题描述

有没有办法去点击一个子菜单的隐藏价值。我希望能够做这样的事

<$p$p><$c$c>driver.findElement(protractor.By.xpath('/html/body/div/div/a')).mouseover.then(function() {
    ptor.findElement(protractor.By.className('名')。gettext的()。然后(功能(结果){
        预期(结果).toBe('我');
    });
});

在该菜单项是不可见的,还是我们的限制与此的时刻。如果这是不可能会出现在周围present这个问题的一种方式。


解决方案

确定,所以经过一个漫长而痛苦的搜索试图找到这个问题的答案我终于通过这个答案就试图回答不同的问题。

大多数我发现解释,我们必须在WebElement的形式使用操作,然后将文档强制转换成Javascript和它传递一个脚本元素与点击操作的数组的形式。

好同种放在这里,但有一些修改。

 描述('',函数(){
    变种ptor = protractor.getInstance();
    VAR司机= ptor.driver;    它('',函数(){
        VAR hiddenElement = driver.findElement(protractor.By.yourchosenlocator(''));
        driver.executeScript(论据[0]。点击(),hiddenElement)。然后(函数(){
            期待(无论).toMatch(什么);
        });
    },30000);
});

你可以看到有没有用webelement和无需转换。

下面是帮助我在我的寻找答案的来源

<一个href=\"http://stackoverflow.com/questions/17448141/how-do-you-click-on-an-element-which-is-hidden-using-selenium-webdriver\">How你使用硒的webdriver这是隐藏在元素上点击?

硒的webdriver - 如何在一个隐藏的LINK或菜单中单击

<一个href=\"http://stackoverflow.com/questions/12371228/selenium-webdriver-hidden-select-and-anchor\">Selenium的webdriver - 隐藏的选择和锚[复制]

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.

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);
});

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

How do you click on an element which is hidden using Selenium Webdriver?

SELENIUM WEBDRIVER – HOW TO CLICK ON A HIDDEN LINK OR MENU

Selenium WebDriver - hidden select and anchor [duplicate]

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

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