[英]Select multiple elements with same id - WebDriverJS
我必須使用Selenium
, WebDriverJS
和Jasmine
創建一個測試,該函數僅在單擊連接到該div
的按鈕時才顯示div
的內容,並隱藏具有相同id
所有其他元素。
這是需要測試的功能,這是我到目前為止編寫的測試的摘要:
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()
並創建一個腳本以使用display:none
定位所有divs
可以解決?
提前感謝您的回復!
我更願意通過計算不可見元素的數量來解決此問題而不使用.isDisplayed()
。 由於所有元素都將具有display:none
,這將確保不顯示元素。
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.findElements(webdriver.By.xpath('//div[contains(@class, "hide") and contains(@style, "display: none")]'))
.then(function(elements) {
expect(elements.length).toBe(expectedCount);
})
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.