Conditional class names are not supported. Consider searching for a single class name and filtering results

I use the driver.findelement by.classname method to read an item in firefox, but I get: "Conditional class names are not supported. Consider searching for a single class name and filtering the results." An exception

here is my code

driver.FindElement(By.ClassName("bighead crb")).Text.Trim().ToString()

//and here is how the html of browser looks like

<form action="#" id="aspnetForm" onsubmit="return false;">
    <section id="lx-home" style="margin-bottom:50px;">
  <div class="bigbanner">
    <div class="splash mc">
      <div class="bighead crb">LEAD DELIVERY MADE EASY</div>
    </div>
  </div>
 </section>
</form>
+4
source share
2 answers

No, your own answer is not the best in terms of your question.

Imagine you have HTML like this:

<div class="bighead ght">LEAD DELIVERY MADE HARD</div>
<div class="bighead crb">LEAD DELIVERY MADE EASY</div>

driver.FindElement(By.ClassName("bighead")) div, , . , , - driver.FindElement(By.ClassName("bighead crb")), , , , .

By.CssSelector By.XPath. :

CssSelector ():

driver.FindElement(By.CssSelector(".bighead.crb")); // flexible, match "bighead small crb", "bighead crb", "crb bighead", etc.
driver.FindElement(By.CssSelector("[class*='bighead crb']")); // order matters, match class contains  "bighead crb"
driver.FindElement(By.CssSelector("[class='bighead crb']")); // match "bighead crb" strictly

XPath ():

driver.FindElement(By.XPath(".//*[contains(@class, 'bighead') and contains(@class, 'crb')]")); // flexible, match "bighead small crb", "bighead crb", "crb bighead", etc.
driver.FindElement(By.XPath(".//*[contains(@class, 'bighead crb')]")); // order matters, match class contains string "bighead crb" only
driver.FindElement(By.XPath(".//*[@class='bighead crb']")); // match class with string "bighead crb" strictly
+18

, :

driver.FindElement(By.ClassName("bighead")).Text.Trim().ToString(); //instead of 
driver.FindElement(By.ClassName("bighead crb")).Text.Trim().ToString();

html , .

+2

All Articles