I am currently having issues with locating an pseudo element for a web page. I have checked other articles to use javascript and tried but it still isnt getting it. Below is a screenshot of what the html is like and the code I wrote to get property and to be able to click on it. Your help will be needed guys

enter image description here

<div class="article-actions" xpath="1"><app-article-meta><div class="article-meta"><a href="/profile/test1234"><img src="https://static.productionready.io/images/smiley-cyrus.jpg"></a><div class="info"><a class="author" href="/profile/test1234"> test1234 </a><span class="date"> June 29, 2021 </span></div><span><a class="btn btn-sm btn-outline-secondary" href="/editor/sdsd-r6g7gi"><i class="ion-edit"></i> Edit Article </a><button class="btn btn-sm btn-outline-danger disabled"><i class="ion-trash-a"></i> Delete Article </button></span><span hidden=""><app-follow-button><button class="btn btn-sm action-btn btn-outline-secondary"><i class="ion-plus-round"></i> &nbsp; Follow test1234
</button></app-follow-button><app-favorite-button><button class="btn btn-sm btn-outline-primary"><i class="ion-heart"></i> Favorite Article <span class="counter">(0)</span></button></app-favorite-button></span></div></app-article-meta></div>
WebElement pseudoEle = driver.findElement(By.xpath("//button//i[@class=\"ion-trash-a\"]/parent::button"));
String display = ((JavascriptExecutor)driver).executeScript("return window.getComputedStyle(arguments[0], ':before').getPropertyValue('content');",pseudoEle).toString();

I also need to be able to click on the element. Note the xpath returns two of the pseudo element that are identical on the page.

1 Answer 1


While working in a testing company we are facing challenges on daily basis specially in automation. JavaScript is little bit tricky in playing those challenges. Please try the below syntax and try to fetch the elements.

String script = "return window.getComputedStyle(document.querySelector('.btn.btn-sm.btn-outline-primary'),':after').getPropertyValue('content')";

IJavaScriptExecutor js = (IJavaScriptExecutor)_driver;

String content = (String) js.ExecuteScript(script);

Here content contains the required elements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.