<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] 前言 有些class屬性中間有空格,如果直接復制過來定位是會報錯的InvalidSelectorException: Message: The given selector u-label f-dn is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: Compound class names not permitted 這個報錯意思是說定位語法錯了。 <br /> ## 一、定位帶空格的class屬性 1. 以126郵箱為例:http://mail.126.com/,定位賬號輸入框 ![](https://img.kancloud.cn/ca/85/ca8590cab0c0ea3886226914610fa127_1423x696.png) 2. 如果直接復制過來用class屬性定位是會報錯的 ![](https://img.kancloud.cn/88/e8/88e814acf758fac655201b4ccf4ce0a8_745x162.png) <br /> ## 二、class屬性科普 1. class屬性中間的空格并不是空字符串,那是間隔符號,表示的是一個元素有多個class的屬性名稱 (class屬性是比較特殊的一個,除了這個有多個屬性外,其它的像name,id是沒多個屬性的) ![](https://img.kancloud.cn/90/25/90251886819b73a5954145151dafec86_885x445.png) 2. 想補習html基礎知識的可以參考菜鳥教程:http://www.runoob.com/html/html-attributes.html <br /> ## 三、class定位 1. 既然知道class屬性有空格是多個屬性了,那定位的時候取其中的一個就行(并且要唯一),也就是說class="j-inputtext dlemail j-nameforslide",取j-inputtext、dlemail和 j-nameforslide都是可以的,這樣這個class屬性在頁面上唯一就行。 ![](https://img.kancloud.cn/cf/33/cf338b53ceb74e6a82bd9948b62aa800_875x215.png) 2. 那么問題來了:如何才知道這個元素的某個屬性是不是在頁面上是唯一的呢? <br /> ## 四、判斷元素唯一性 1. F12切換到HTML界面,在搜索框輸入關鍵字搜索,如:j-inputtext,然后按回車搜索,看頁面上有幾個class屬性中有j-inputtext這個屬性的,就知道是不是唯一的了。 ![](https://img.kancloud.cn/54/92/5492a1a354ff23b0576869f157e9baa5_1229x680.png) <br /> ## 五、class屬性不唯一怎么辦 1. 如果這個class的多個屬性都不是唯一的咋辦呢,元素不唯一也不用怕,可以用復數定位,把所有的相同元素定位出來,按下標取第幾個就行。 ![](https://img.kancloud.cn/28/1b/281b83202676f38b7bdc37248f2e0555_848x234.png) <br /> ## 六、css定位 1. css來定位class屬性的元素前面加個點(.)就行,然后空格變成點(.)就能定位了 2. 當然css也可以取class屬性的其中一個屬性(頁面上唯一的)來定位,定位方法是靈活多變的 ![](https://img.kancloud.cn/24/8a/248acc40c4686b239de6c13cfd8ed3c4_848x334.png) <br /> ## 七、參考代碼 ``` from selenium import webdriver driver = webdriver.Chrome() driver.get("http://mail.126.com/") driver.implicitly_wait(20) driver.switch_to.frame("x-URS-iframe") # 方法一:取單個class屬性 driver.find_element_by_class_name("dlemail").send_keys("yoyo") driver.find_element_by_class_name("dlpwd").send_keys("12333") # 方法二:定位一組取下標定位(乃下策) # driver.find_elements_by_class_name("j-inputtext")[0].send_keys("yoyo") # driver.find_elements_by_class_name("j-inputtext")[1].send_keys("12333") # 方法三:css定位 # driver.find_element_by_css_selector(".j-inputtext.dlemail").send_keys("yoyo") # driver.find_element_by_css_selector(".j-inputtext.dlpwd").send_keys("123") # 方法四:取單個class屬性也是可以的 # driver.find_element_by_css_selector(".dlemail").send_keys("yoyo") # driver.find_element_by_css_selector(".dlpwd").send_keys("123") ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看