1. <tfoot id='RrfYk'></tfoot>

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

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

        • <bdo id='RrfYk'></bdo><ul id='RrfYk'></ul>
      2. &quot;find_element_by_name(&#39;name&#39;)&q

        时间:2024-08-10

          • <bdo id='22heD'></bdo><ul id='22heD'></ul>
              1. <legend id='22heD'><style id='22heD'><dir id='22heD'><q id='22heD'></q></dir></style></legend>
                  <tbody id='22heD'></tbody>

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

                <tfoot id='22heD'></tfoot>
                • <small id='22heD'></small><noframes id='22heD'>

                  本文介绍了&quot;find_element_by_name(&#39;name&#39;)&quot;和&QOOT;FIND_ELEMENT(BY NAME,&#39;NAME&#39;)&QUOT;之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  示例:

                  # method 1
                  from selenium import webdriver
                  
                  PATH = '...'
                  driver = webdriver.Chrome(PATH)
                  driver.get('https://google.com')
                  driver.find_element_by_name('q').send_keys('test')
                  
                  # method 2
                  from selenium import webdriver
                  from selenium.webdriver.common.by import By
                  
                  PATH = 'c:\Program Files (x86)\chromedriver.exe'
                  driver = webdriver.Chrome(PATH)
                  driver.get('https://google.com')
                  driver.find_element(By.NAME, 'q').send_keys('test')
                  

                  基本上,我想知道:

                  1-两者之间有什么不同?如果有,是什么?

                  2-一般来说,这两者有什么区别吗?

                  find_element_by_class_name(el): find_element(By.CLASS_NAME, el); 
                  
                  find_element_by_name(el): find_element(By.NAME, el)
                  

                  3-执行第一个方法时为什么显示DeprecationWarning

                  推荐答案

                  正如@guihva也提到的,这两行没有区别:

                  driver.find_element_by_name('q')
                  

                  driver.find_element(By.NAME, 'q')
                  

                  如同当前版本的selenium4Python客户端find_element_by_name(name)在幕后仍然调用:

                  self.find_element(by=By.NAME, value=name)
                  

                  但与DeprecationWarning一起。

                  find_element_by_name()当前实现如下:

                  def find_element_by_name(self, name) -> WebElement:
                      """
                      Finds an element by name.
                  
                      :Args:
                       - name: The name of the element to find.
                  
                      :Returns:
                       - WebElement - the element if it was found
                  
                      :Raises:
                       - NoSuchElementException - if the element wasn't found
                  
                      :Usage:
                          ::
                  
                              element = driver.find_element_by_name('foo')
                      """
                      warnings.warn(
                          "find_element_by_* commands are deprecated. Please use find_element() instead",
                          DeprecationWarning,
                          stacklevel=2,
                      )
                      return self.find_element(by=By.NAME, value=name)
                  

                  为什么要进行此更改

                  As@AutomatedTestermentions:

                  决定简化跨语言的API,这就做到了这一点。

                  这篇关于&quot;find_element_by_name(&#39;name&#39;)&quot;和&QOOT;FIND_ELEMENT(BY NAME,&#39;NAME&#39;)&QUOT;之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在Kivy中制作渐变背景 下一篇:如何寻址在Python Selenium中不可调用的模块对象

                  相关文章

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

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

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