简体   繁体   中英

selenium-webdriver npm detect successful link click

Is there a reliable way to detect a successful link click to an unknown page with selenium-webdriver npm ?

I need to be able to test a simple page load on my site and check that an outbound link to an unknown page loads up ok. The site i am working on is a holiday letting site that displays a link to the hotels own page (so the contents of the target link will be completely unknown), i cannot find any way of reliably checking if the hotels website loads up or not using selenium.

Here is the test i have got thus far:

//1 load up the url
    driver.get( testConfig.url + '/britain/england/cornwall/hotel88').then(function(){
        //2 get current page html title
        var title = driver.findElement(By.css('title'));
        title.getInnerHtml().then(function(html) {
            var controlTestTitle = html;
            //3 now move onto the owners link
            driver.findElement(By.css('.details-web')).click().then(function(){
                driver.wait(function(){
                    return driver.isElementPresent(By.css("title"));
                }, testConfig.timeout).then(function(){
                    var title = driver.findElement(By.css('title'));
                    title.getInnerHtml().then(function(html) {
                        //check that this title is not the same
                        if( html != controlTestTitle ){
                            if (callback) {
                                callback(callback);
                            }
                        } else {
                            throw 'the page title did not change when moving onto the owners website';
                        }
                    });
                });
            });
        });
    });

The above code is simply checking that the target page's html title is not the same as the original one.. but when the test runs i do not see the hotel's site actually loading up so i am not confident that the test is actually a success or not.

I did find this site trying to explain it, however the code is java which i do not know.. plus (as you can likely tell from the nature of this post) i am very new to selenium...

According to your comment, and your desire to use selenium for this task:

What you can do is , find at least 1 element on the page that would appear after clicking the link.

Once you click the link, simply validate that the one element you found, is present on the page. If not, then that means the page didn't load correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM