I'm trying to highlight all the elements of a page, using Selenium to inject some JavaScript and CSS.
However when I run my test i'm only getting back errors complaining that it can't find the elements.
'javascript error: $ is not defined
The page i'm using is:
https://statsroyale.com/decks/popular and i'm trying to highlight each of the cards in a deck.
The selector that i'm using is:
public IList<IWebElement> AllCardsInPopularDecks => Driver.FindElements(By.XPath("//*[@class='popularDecks__decklist']//img"));
And my JavaScript method is:
internal void HighlightElement(IWebElement element)
{
var jsDriver = (IJavaScriptExecutor)Driver;
string highlightJavascript = @"$(arguments[0]).css({ ""border-width"" : ""2px"", ""border-style"" : ""solid"", ""border-color"" : ""red"", ""background"" : ""yellow"" });";
jsDriver.ExecuteScript(highlightJavascript, new object[] { element });
}
My method which is calling the test that is:
public void HighlightAllCards()
{
foreach (var card in Map.AllCardsInPopularDecks)
{
HighlightElement(card);
}
}
And my test case is:
[TestMethod]
public void TestOne()
{
Homepage.GoTo();
Homepage.GoToPopularDecks();
Homepage.HighlightAllCards();
}
(This only a test... so ignore the name!)
I've tried to debug the issue and it seems that a element is being found. But it's not being passed to my JS method.