簡體   English   中英

選擇具有相同ID的多個元素-WebDriverJS

[英]Select multiple elements with same id - WebDriverJS

我必須使用SeleniumWebDriverJSJasmine創建一個測試,該函數僅在單擊連接到該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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM