MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / ClassName

Method ClassName

dotnet/src/webdriver/By.cs:238–259  ·  view source on GitHub ↗

Gets a mechanism to find elements by their CSS class. The CSS class to find. A object the driver can use to find the elements. If an element has many classes then this will match against each of them. For example if the value is "one two onone", then the following values for the className parame

(string classNameToFind)

Source from the content-addressed store, hash-verified

236 /// className parameter will match: "one" and "two".</remarks>
237 /// <exception cref="ArgumentNullException">If <paramref name="classNameToFind"/> is null.</exception>
238 public static By ClassName(string classNameToFind)
239 {
240 if (classNameToFind == null)
241 {
242 throw new ArgumentNullException(nameof(classNameToFind), "Cannot find elements when the class name expression is null.");
243 }
244
245 string selector = "." + EscapeCssSelector(classNameToFind);
246 if (selector.Contains(" "))
247 {
248 // Finding elements by class name with whitespace is not allowed.
249 // However, converting the single class name to a valid CSS selector
250 // by prepending a '.' may result in a still-valid, but incorrect
251 // selector. Thus, we short-circuit that behavior here.
252 throw new InvalidSelectorException("Compound class names not allowed. Cannot have whitespace in class name. Use CSS selectors instead.");
253 }
254
255 return new By(CssSelectorMechanism, selector)
256 {
257 Description = "By.ClassName[Contains]: " + classNameToFind
258 };
259 }
260
261 /// <summary>
262 /// Gets a mechanism to find elements by a partial match on their link text.

Calls

no outgoing calls