Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A way of clicking on hidden elements in protractor end to end tests

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.

like image 377
Ian Richards Avatar asked Aug 23 '13 15:08

Ian Richards


People also ask

How do you click hidden elements with a protractor?

perform(); ptor. element. all(by. tagName('i')).

How do you handle hidden elements?

In case an element is a part of the form tag, it can be hidden by setting the attribute type to the value hidden. Selenium by default cannot handle hidden elements and throws ElementNotVisibleException while working with them. Javascript Executor is used to handle hidden elements on the page.

What is protractor and Jasmine?

Protractor – As discussed earlier, it is a wrapper over WebDriver JS especially designed for angular apps. Jasmine – A behavior-driven development framework for testing the JavaScript code. We can write the tests easily with Jasmine. WebDriver JS – A Node JS binding implementation for Selenium 2.0/WebDriver.

Why protractor for Angular applications?

Protractor supports Angular-specific locator strategies, which allows you to test Angular-specific elements without any additional setup effort.


1 Answers

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]

like image 52
Ian Richards Avatar answered Sep 28 '22 07:09

Ian Richards