2016-11-28 46 views
3

對於量角器我很陌生,想知道爲什麼我的按鈕在使用selenium webdriver管理器在量角器中運行測試時沒有被點擊。量角器css選擇器無法識別的元素

按鈕:

<button class="preview-toggle" icon="add" icon-only="" right="" ng-reflect-router-link="add"></button> 

在鑲邊時,我使用下面的選擇:[納克 - 反射 - 路由器鏈路=「添加」]所需的元素被發現。

我量角器,conf.js:

exports.config = { 


seleniumAddress: 'http://localhost:4444/wd/hub', // This is targetting my local running instance of the selenium webdriver 

specs: [ 
    './features/**/*.feature' 
], 

capabilities: { 
    browserName: 'chrome' 
}, 

framework: 'custom', //We need this line to use the cucumber framework 

frameworkPath: require.resolve('protractor-cucumber-framework'), // actual framework 

cucumberOpts: { 
    format: 'pretty', 
    require: './features/step_definitions/**/*.js' // This is where we'll be writing our actual tests 
}, 

useAllAngular2AppRoots: true 

};

我的要素類是一個簡單的

Feature: Cool_feature 
    Scenario: I do something awesome 
    Given I open up the application 
    When I click on add 
    Then I should be the best 

我test.js類

test = function() { 


this.Given(/^I open up the application$/, function (callback) { 
    browser.get('foo.com').then(callback); 
}); 

this.When(/^I click on add$/, function (callback) { 
    // Write code here that turns the phrase above into concrete actions 
    browser.element(by.css('[ng-reflect-router-link="add"]')).click().then(callback); 
}); 

this.Then(/^I should be the best"$/, function (callback) { 

}); 
}; 
module.exports=test; 
+0

你不必給'browser.element'。它應該是'element(by.css('[ng-reflect-router-link =「add」]'))' –

回答

0

嘗試用按鈕,您的前綴屬性選擇:

element(by.css('button[ng-reflect-router-link=add]')); 
1
element(by.css(".preview-toggle")); 

應該工作

+0

感謝您的回答,我現在能夠找到元素。事情是該項目只能在Firefox中找到,而不是在鉻。我們需要使用chrome進行測試,因爲它對此瀏覽器是最優化的。即使當我選擇全身並在控制檯中打印時,我也沒有得到任何價值。 有什麼建議嗎? – remonh87

+0

試着等待。這可能是測試更快,通常我們知道chrome比其他瀏覽器更快: –

1
var el = element(by.css(".preview-toggle")); 
browser.wait(EC.presenceOf(element(by.css(".preview-toggle"))), 30000).then(function() { 
     browser.wait(EC.visibilityOf(element(by.css(".preview-toggle"))), 30000).then(function() { 
      browser.wait(EC.elementToBeClickable(element(by.css(".preview-toggle"))), 30000).then(function() { 
       el .click() 
}); 
}); 
}); 
+0

奇怪,但在5000 ms超時後收到以下消息: org.openqa.selenium.WebDriverException:元素在點上不可點擊(1850年,128年)。其他元素會收到點擊: remonh87

+0

好,我們正在一個良好的軌道上。你有一些阻止點擊的元素。 –

1

你有一些裝載元素,等待成爲無形的:

browser.wait(EC.invisibilityOf(element(by.id("loading-app-content"))), 30000).then(function() { 
var el = element(by.css(".preview-toggle")); 
browser.wait(EC.presenceOf(element(by.css(".preview-toggle"))), 30000).then(function() { 
    browser.wait(EC.visibilityOf(element(by.css(".preview-toggle"))), 30000).then(function() { 
     browser.wait(EC.elementToBeClickable(element(by.css(".preview-toggle"))), 30000).then(function() { 
      el .click() 
}); 
}); 
}); 
}); 
0

使用這樣的:元素(by.className( 「預覽切換」));它肯定會工作

0

感謝您的幫助,至少我得到了在Firefox和phantomjs工作的選擇器。我用下面的代碼,以解決學生選課和組件得到阻止微調:

test = function() { 
var EC = protractor.ExpectedConditions; 
var el= element(by.className("preview-toggle")); 


this.Given(/^I open up the application$/, function (callback) { 

    browser.get('foo.nl').then(callback); 
}); 

this.When(/^I click on add$/, function (callback) { 
    // Write code here that turns the phrase above into concrete actions 

    //this is for waiting until loading is done 
    browser.wait(EC.invisibilityOf(element(by.id("loading-app-content"))), 30000).then(function() { 
     //check if the button is there 
     browser.wait(EC.presenceOf(element(by.css(".preview-toggle"))), 30000).then(function() { 
      //check if the element is visible and clickable then click it 
      browser.wait(EC.visibilityOf(element(by.css(".preview-toggle"))), 30000).then(function() { 
       browser.wait(EC.elementToBeClickable(element(by.css(".preview-toggle"))), 30000).then(function() { 
        el.click().then (callback); 
       }); 
      }); 
     }); 
    }); 

}); 

this.Then(/^I should be the best$/, function (callback) { 
    callback(); 
}); 


}; 
module.exports=test; 

問題是因爲硒的webdriver在鉻崩潰我鉻司機沒有找到DOM節點但那是另一個問題應對。 :-)

相關問題