Reputation: 1
This line code returns number of elements.
document.getElementsByClassName("entry entryWriteable");
-> returns 70 elements
I want to implement a loop so that, Below line of code will execute for all the element.
document.getElementsByClassName("entry entryWriteable")[i].value;
Can any one help me how to impliment in C# selenium ?
Upvotes: 0
Views: 5948
Reputation: 985
Like Denis said, but if you need a return value of all values in entire element array, then try:
using OpenQa.Selenium.Webdriver.Extensions
driver.ExecuteJavascript<string>(`
var els = document.getElementsByClassName("entry entryWriteable");
string returnAllElementTexts = "";
for(var i = 0; i < els.length; i++) {
returnAllElementTexts += els[i] + "|";
}
return returnAllElementText;`);
This will return a pipe-delimited string of all values. Split on pipe from C#. Is that what you wanted? All text values from array of elements?
Upvotes: 0
Reputation: 3718
In order to execute JS in selenium on C# you should use the next code:
((IJavaScriptExecutor) Driver).ExecuteScript("your code"));
So you can execute any JS code you want.
The ExecuteScript
returns object
so probably you can typify it.
Upvotes: 3