繁体   English   中英

selenium-webdriver npm检测成功的链接单击

[英]selenium-webdriver npm detect successful link click

有没有一种可靠的方法可以检测到使用selenium-webdriver npm成功链接到未知页面的链接?

我需要能够测试网站上的简单页面加载,并检查指向未知页面的出站链接是否可以正常加载。 我正在工作的网站是一个放假的网站,它显示指向酒店自己页面的链接(因此,目标链接的内容将是完全未知的),我找不到可靠地检查酒店网站是否已加载的任何方法使用硒。

这是到目前为止我得到的测试:

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

上面的代码只是检查目标页面的html标题与原始页面的html标题是否不同..但是当测试运行时,我没有看到酒店的网站实际加载完毕,因此我不确定测试是否成功或不。

我确实找到了这个网站,试图解释它,但是代码是我不知道的java .. plus(您可能从这篇文章的性质可以看出)我对硒很陌生...

根据您的评论,以及您希望使用硒完成此任务的愿望:

您可以做的是 ,点击链接后在页面上至少找到1个元素。

单击链接后,只需验证页面上是否存在找到的一个元素。 如果不是,则意味着页面未正确加载。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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