There is Selenium + TestNG.

Test: check the discovery (enlarged image when hovering on the photo) photos. But it happens that the photo without this option, because of what the test falls.

Question: is there an option to put an if (and how correctly) that it checks for the presence of a zoom? And if this zoom is absent, then skip the test / step.

While tried if(элемент.isDisplayed()) {Тест} else {} . But he is still looking for him and does not miss the test if there is no zoom.

  • More precisely the question is - how to make a check for the presence of css elements? - sank

1 answer 1

Get css attribute value done using getCssValue('value') method

 String value = component.getCssValue("cssValue"); //пример для background-color String value = component.getCssValue("background-color"); 

The output will be null if cssValue not present, otherwise the string representation of this css attribute will be returned.

Update

To make sure that the div.zoomPicture elements are not on the page, you can try to find all such elements (via driver.findElements ) and if the size of the resulting collection is 0, then the div.zoomPicture elements are not on the page.

  • Thanks for the answer, but in this case I do not need the characteristics of the element (although an interesting thing), namely, to check in the site code of the page whether it is or not. Example: there are some div.zoomPicture pages, and some not. How to check is this or not? And the resulting overgrowth: if there is no element, then how to boil the test so that it is not considered failed? - sank
  • @sank see response update - Andrew Bystrov
  • Thanks It works. List <WebElement> listOfZoomPicture = driver.findElements (By.cssSelector ("div.zoomLens")); if (listOfZoomPicture.size ()> 0) {Test text} else {System.out.println ("There is no zoom in the photo");} - sank