Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
766 views
in Technique[技术] by (71.8m points)

angularjs - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...