量角器:browser.wait函数,isElementPresent超时

时间:2016-07-18 22:25:48

标签: protractor

这是我的代码。由于某种原因,它无法检测到存在的元素,只是超时。网站是有角的。我尝试过isPresent,以及ExpectedConditions,但它仍然超时。出于某种原因,无论我如何尝试找到它,它都无法检测到该元素。我也试过了多个元素。我对任何想法持开放态度。

    browser.wait(function()
    {
    return browser.isElementPresent(by.xpath('//[@id="ngdialog1"]/div[2]/div/div')).then(function(present)
    {    
        console.log('\n' + 'looking for element')
        if(present)
        {
        console.log('\n' + 'recognized dialog');
        var jccSelect = element(by.xpath('//*[@id="ghId_GameSelectBottomRow"]/div[1]'));
        jccSelect.click();

        return true;
    }
})}, 50000);

});

1 个答案:

答案 0 :(得分:2)

您已在 if {return true;} 中保留 返回 语句,如果有现值是 false 然后控件将不会返回,这就是为什么你的时间超时问题。

我重新安排了以下代码:

 EC = protractor.ExpectedConditions;
 targetElement=element(by.xpath('//[@id="ngdialog1"]/div[2]/div/div'));

 browser.wait(function(){
 return EC.visibilityOf(targetElement).call().then(function(present){    
      console.log('\n' + 'looking for element')
      if(present)
        {
         //do what would you like to do
         return true;
        }
       else{
           //do what would  you like to do
           return false;
        }
 });
}, 50000);
相关问题