Alternative to: Element Should Be Visible

Hello all,

I am wondering whether there is an alternative to Element Should Be Visible keyword from SeleniumLibrary in the Browser library?

It is a useful keyword to me, as well as some other "Should be"s. Did you replace it in some other way in your own tests?

Thank you and best regards,
J

You can use get element states

2 Likes

As _daryl mentioned:

Get Element States is the keyword you are looking for.

It can not only check for visibility but also its absence (hidden) or if an element is enabled or readonly etc.

Because it “returns” multiple states at the same time, you check if a desired state is contained in the list of returned states.

Get Element States    id=yourelement    contains    visible

Or even more information at the same time:

Get Element States    id=yourelement    contains    visible    enabled    editable

Or the opposite if an element is “hidden”

Get Element States    id=yourelement    contains    hidden

You can also watch the talk from last RoboCon

3 Likes

Thank you very much to both of you. This does the trick indeed!

1 Like

Hi ,
Can I use Get Element States when I want to check that an element is visible and contains the text “xyz” ? If yes how I should use it? Could you give me an example?
Thank you in advance for your answer,
Monika

You could use:

Get Element States    css=yourelement:has-text("xyz")                contains    visible

Get Element States    xpath=yourelement[contains(text(), "xyz")]     contains    visible

or alternatively:

Get Element States    id=yourelement    contains    visible
Get Text              id=yourelement.   *=          xyz

@Monika If want to do something with an element that is visible and has a certain text, you can also chain engines and do something like this:

Highlight Elements a >> visible=true >> text=new

This will highlight all a elements that a visible and contain the text ‘new’

1 Like