I'm using VBA Selenium Basic to parse a HTML document, trying to change the attribute style
from a td
element. I tried to find methods like webelement.RemoveAtrr
, webelement.SetAtrr
or the like in vain.
After searching through DuckDuckGo and Stack Overflow, I came to think Selenium Basic can't remove, change or insert an attribute -- only read them. So I tried to do it using javascript.
Then I came to browser console and used the following lines:
var cell = document.querySelector('body > div > form:nth-child(5) > table > tbody > tr:nth-child(1) > tr:nth-child(1)');
cell.removeAttribute('class');
cell.setAttribute('style','background-color: #00FF7F;';
The javascript works fine on the page, discard old class information and adding new style information. So, I came to VBA and tried this:
oChrome.ExecuteScript "var sfCell = document.querySelector('body > div > form:nth-child(5) > table > tbody > tr:nth-child(1) > td:nth-child(1)');"
oChrome.ExecuteScript "sfCell.removeAttribute('class');"
oChrome.ExecuteScript "sfCell.setAttribute('style','background-color: #00FF7F;';"
But it didn't work. The first line runs but doesn't create the variable, as I can see in Console window. The second line retrieves an error from javascript, not from VB: sfCel.removeAttribute is not a function
.
How should I perform javascript multiline instructions using ExecuteScript? I also accept ways to remove and change attributes not using javascript, but I'm honestly curious about the problem in the above code.
Thanks!