0
我要創建與Selenium
,WebDriverJS
和Jasmine
用於顯示連接到div
點擊按鈕只有當div
內容的功能測試,並隱藏所有其他元素與id
相同。選擇具有相同ID的多個元素 - WebDriverJS
This是需要測試的功能,這是迄今爲止我已經寫了測試的一個片段:
it('should display "BILL2" when the second picture is clicked and hide the others', function() {
driver.findElement(webdriver.By.css('#img_bill2')).click()
.then(function(){
driver.findElement(webdriver.By.css('#bill2')).isDisplayed()
.then(function(displayed) {
expect(displayed).toBe(true);
});
})
.then(function() {
driver.findElement(webdriver.By.xpath('//div[@class="hide", @style="display:none"]')).isDisplayed()
.then(function(displayed) {
expect(displayed).toBe(false);
})
});
});
我堅持在這裏,因爲我想選擇所有的元素,除了當前顯示的那個。
你對如何解決這個問題有想法嗎?也許使用executeScript()
並創建一個腳本來定位所有divs
與display:none
風格可以解決嗎?
在此先感謝您的答覆!
不是找到一個元素,而是找到所有具有相同xpath的元素並聲明元素的個數。由於所有元素都有'@ style =「display:none」'來確保這些元素不被顯示。 –
是的,這是我解決它的方法。我簡單地使用了'xpath('// div [contains(@class,「hide」)並且包含了(@style,「display:none」)]')'和ti。由於你的解決方案有效,你是第一個評論,你可以發佈它作爲答案,並獲得積分:) –
Plz接受我的答案。 :) –