Reputation: 53
Here's my code:
@FindBy(css = "span.et_pb_image_wrap img[title='globeathome ']")
WebElement header1
I created a method for this since I am using a POM design pattern:
public boolean isImgDisplayed()
{
return header1.isDisplayed();
}
here's the HTML tag :
<span class="et_pb_image_wrap ">
<img src="https://3p4expkcmfr6hgud4mqt.stratpoint.com/wp-content/uploads/globeathome.png" alt="globeathome stratpoint" title="globeathome" srcset="https://3p4expkcmfr6hgud4mqt.stratpoint.com/wp-content/uploads/globeathome.png 2855w, https://3p4expkcmfr6hgud4mqt.stratpoint.com/wp-content/uploads/globeathome-1280x1037.png 1280w, https://3p4expkcmfr6hgud4mqt.stratpoint.com/wp-content/uploads/globeathome-980x794.png 980w, https://3p4expkcmfr6hgud4mqt.stratpoint.com/wp-content/uploads/globeathome-480x389.png 480w" sizes="(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) and (max-width: 1280px) 1280px, (min-width: 1281px) 2855px, 100vw">
</span>
My problem is the isDisplayed() is returning false even if the WebElement is present.
Upvotes: 1
Views: 2480
Reputation: 950
check doc -> https://developers.perfectomobile.com/display/TT/Difference+between+Selenium+visibility+methods
isDisplayed()
:
This method determines if an element is displayed on the screen or not i.e. whether its width and height are greater than zero, it isn't hidden by CSS, etc. If the element is present on the page, but has style="display:none;" then isDisplayed() will return false.. It returns true if the element is displayed and false if it is not. Advantage of this method is that it avoids parsing an elements style attribute. isDisplayed is used in cases where element is present in DOM and you need to check whether it is displayed or not in the UI. It is never used to check whether an element is present in the DOM.
as @Razvan said image may not be loaded
Upvotes: 2