<tfoot id='JGbZ8'></tfoot>

        <bdo id='JGbZ8'></bdo><ul id='JGbZ8'></ul>

      <small id='JGbZ8'></small><noframes id='JGbZ8'>

    1. <legend id='JGbZ8'><style id='JGbZ8'><dir id='JGbZ8'><q id='JGbZ8'></q></dir></style></legend>
      <i id='JGbZ8'><tr id='JGbZ8'><dt id='JGbZ8'><q id='JGbZ8'><span id='JGbZ8'><b id='JGbZ8'><form id='JGbZ8'><ins id='JGbZ8'></ins><ul id='JGbZ8'></ul><sub id='JGbZ8'></sub></form><legend id='JGbZ8'></legend><bdo id='JGbZ8'><pre id='JGbZ8'><center id='JGbZ8'></center></pre></bdo></b><th id='JGbZ8'></th></span></q></dt></tr></i><div id='JGbZ8'><tfoot id='JGbZ8'></tfoot><dl id='JGbZ8'><fieldset id='JGbZ8'></fieldset></dl></div>

        不支持复合类名.考虑搜索一个类名并过滤结果

        时间:2023-09-13

        1. <tfoot id='rlBGe'></tfoot>
            <bdo id='rlBGe'></bdo><ul id='rlBGe'></ul>

                <i id='rlBGe'><tr id='rlBGe'><dt id='rlBGe'><q id='rlBGe'><span id='rlBGe'><b id='rlBGe'><form id='rlBGe'><ins id='rlBGe'></ins><ul id='rlBGe'></ul><sub id='rlBGe'></sub></form><legend id='rlBGe'></legend><bdo id='rlBGe'><pre id='rlBGe'><center id='rlBGe'></center></pre></bdo></b><th id='rlBGe'></th></span></q></dt></tr></i><div id='rlBGe'><tfoot id='rlBGe'></tfoot><dl id='rlBGe'><fieldset id='rlBGe'></fieldset></dl></div>

                <small id='rlBGe'></small><noframes id='rlBGe'>

                <legend id='rlBGe'><style id='rlBGe'><dir id='rlBGe'><q id='rlBGe'></q></dir></style></legend>
                    <tbody id='rlBGe'></tbody>

                  本文介绍了不支持复合类名.考虑搜索一个类名并过滤结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 driver.findelement by.classname 方法读取 Firefox 浏览器上的元素,但我得到不支持复合类名.考虑搜索一个类名并过滤结果."异常

                  I am using driver.findelement by.classname method to read an element on firefox browser but i am getting "Compound class names are not supported. Consider searching for one class name and filtering the results." exception

                  这是我的代码

                  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>
                  

                  推荐答案

                  不,就您的问题而言,您自己的答案并不是最好的.

                  No, your own answer isn't the best one in terms of your question.

                  想象一下你有这样的 HTML:

                  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")) 之类的东西,但是就像您在问题中所说的那样,这行不通,因为您需要另一种查找元素的方法按复合类名.

                  driver.FindElement(By.ClassName("bighead")) will find both and return you the first div, instead of the one your want. What you really want is something like driver.FindElement(By.ClassName("bighead crb")), but like you said in your question, this won't work as you need another way to find elements by compound class names.

                  这就是为什么大多数人使用更强大的 By.CssSelectorBy.XPath.那么你有:

                  This why most people use more powerful By.CssSelector or By.XPath. Then you have:

                  CssSelector(最好的):

                  CssSelector (the best):

                  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
                  

                  这篇关于不支持复合类名.考虑搜索一个类名并过滤结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Selenium WebDriver 和浏览器选择文件对话框 下一篇:OpenQA.Selenium.WebDriverException: '无法在 http://localhos

                  相关文章

                  <tfoot id='4g6zb'></tfoot><legend id='4g6zb'><style id='4g6zb'><dir id='4g6zb'><q id='4g6zb'></q></dir></style></legend>
                  <i id='4g6zb'><tr id='4g6zb'><dt id='4g6zb'><q id='4g6zb'><span id='4g6zb'><b id='4g6zb'><form id='4g6zb'><ins id='4g6zb'></ins><ul id='4g6zb'></ul><sub id='4g6zb'></sub></form><legend id='4g6zb'></legend><bdo id='4g6zb'><pre id='4g6zb'><center id='4g6zb'></center></pre></bdo></b><th id='4g6zb'></th></span></q></dt></tr></i><div id='4g6zb'><tfoot id='4g6zb'></tfoot><dl id='4g6zb'><fieldset id='4g6zb'></fieldset></dl></div>
                  • <bdo id='4g6zb'></bdo><ul id='4g6zb'></ul>

                      <small id='4g6zb'></small><noframes id='4g6zb'>