2016-08-04 83 views
-1

应该很简单,我试图点击使用量角器的图像链接。使用量角器查找并单击锚点链接

<a href="//safeweb.norton.com 
    /a> 

我知道我在做很长的路。

var nortonlink = element(by.css('[href="//safeweb.norton.com/"]')); 

    nortonlink.click(); 

    expect(browser.getCurrentUrl()).toEqual('https://safeweb.norton.com/'); 

我的期望一直说它仍然在当前页面上,所以点击没有运行。

回答

4

您可能需要等待,直到您在目标页面。有相关urlIs Expected Condition添加到量角器4:

var nortonlink = $('[href*=safeweb]'); // NOTE: also simplified the selector 
nortonlink.click(); 

var EC = protractor.ExpectedConditions; 
browser.wait(EC.urlIs("https://safeweb.norton.com/"), 5000); 

我不知道,如果你需要在这里结尾的斜线 - 尝试使用和不使用。

1

使用protractor.ExpectedConditions检查链接是否可点击。然后点击它。

var EC = protractor.ExpectedConditions; 

    var nortonlink = element(by.css('[href="//safeweb.norton.com/"]')); 

    nortonlink.click().then(function(){ 
    //wait until page completely loaded 
    browser.wait(function() { 
     return browser.getCurrentUrl().then(function (url) { 
       if(url==!"old url"){  
       return true; 
       } }); 
     }, 8000, 'URL has not changed'); 

    expect(browser.getCurrentUrl()).toEqual('https://safeweb.norton.com/'); 
    }); 
+0

从我所了解的OP设法点击链接没有问题,但URL检查期望失败。 – alecxe

+0

@alecxe你可能是正确的。我认为元素可能不会处于可点击状态。 –

+0

可能是,我希望'click()'在这种情况下失败。会很乐意错误的。谢谢。 – alecxe