简体   繁体   中英

How do I get all the classes of an element?

Please see the code below:

var children3 = child2.FindElements(By.TagName("td"));
foreach (var child3 in children3)
{
var test = child3.GetAttribute("class");
}

test is populated if the element contains one class, however if it is an empty string if the element contains multiple classes. How do I get all the classes of an element?

Even in case of multiple classes:

var test = child3.GetAttribute("class");

Will retrieve the value of class attribute which may consist of multiple classes.

var test = child3.GetAttribute("class");

the test variable contains classes with format "class1 class2 class3", so if you want to get all call in for example array string you can split test variable with space. finally, you will get array with 3 classes is class1, class2, class3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM