0xM4x
0xM4x

Reputation: 470

How to check if an element is a clickable button and not a text?

I'm trying to test a web application. there is an element that sometimes it's just a text and sometimes it's clickable. How can I distinguish between when it's a clickable button and a simple text? (the text inside of the element is the same in both situations.) the only difference is ::after pseudo-elements.

<h2 class="line_10001">
Goal
</h2>

<h2 class="line-10001">
Goal
::after
</h2>   

Thanks for your help :)

Upvotes: 0

Views: 253

Answers (2)

0xM4x
0xM4x

Reputation: 470

I found a solution with help of javascript:

String script = "return window.getComputedStyle(document.querySelector('h2.line_10001'),':after').getPropertyValue('content')";

JavascriptExecutor js = (JavascriptExecutor)driver;
String content = (String) js.executeScript(script);

now if you check the content, if there's no :after in element, the content will be "none".

Upvotes: 2

Neagu V
Neagu V

Reputation: 480

You can use css selector and nth-child. For example for the first element will be:

h2:nth-child(1)

and for the second

h2:nth-child(2)

You can test the select in the browser console to see how if it works.

 $("h2:nth-child(1)");
 $("h2:nth-child(2)");

Get them both and check using WaitDriver which one is clickable and click on it.

Upvotes: 0

Related Questions