Reputation: 1263
I have to create a test with Selenium
, WebDriverJS
and Jasmine
for a function that displays the content of a div
only when the button connected to that div
is clicked, and hide all the other elements with the same id
.
This is the function that needs to be tested, and this is a snippet of the test I have written so far:
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);
})
});
});
I am stuck here since I would like to select all the elements, except the one that is currently shown.
Do you have an idea on how to solve this issue? Maybe using executeScript()
and create a script to locate all the divs
with display:none
style can be a solution?
Thanks in advance for your replies!
Upvotes: 0
Views: 854
Reputation: 3058
I'd prefer to solve this without using .isDisplayed()
by counting the numbers of invisible elements. Since all elements would have display:none
which will ensure that the elements are not displayed.
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);
})
});
});
Upvotes: 1