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
<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> 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();
System.out.println(display);
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.
Source: Read More