• <bdo id='zT44b'></bdo><ul id='zT44b'></ul>

    <tfoot id='zT44b'></tfoot>

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

        <legend id='zT44b'><style id='zT44b'><dir id='zT44b'><q id='zT44b'></q></dir></style></legend>

        python, selenium中用于切换帧的函数

        时间:2023-07-04
          <tbody id='k2ql9'></tbody>
          • <bdo id='k2ql9'></bdo><ul id='k2ql9'></ul>

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

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

                  本文介绍了python, selenium中用于切换帧的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在寻找一种可以更轻松地在两个帧之间切换的功能.现在,每次我需要在帧之间切换时,我都通过以下代码来做到这一点:

                  I'm looking for a function that makes it easier to switch between two frames. Right now, every time I need to switch between frames, I'm doing this by the following code:

                  driver.switch_to.frame(driver.find_element_by_css_selector("frame[name='nav']"))
                  
                  driver.switch_to.frame(driver.find_element_by_css_selector("frame[name='content']"))
                  

                  我的目标是获得一个函数,该函数接受一个参数来更改导航或内容,因为其余部分基本相同.

                  My goal is to get a function that takes an argument just to change nav or content since the rest is basically the same.

                  我已经尝试过的是:

                  def frame_switch(content_or_nav):
                  x = str(frame[name=str(content_or_nav)] #"frame[name='content_or_nav']"
                  driver.switch_to.frame(driver.find_element_by_css_selector(x))
                  

                  但它给了我一个错误

                   x = str(frame[name=str(content_or_nav)]
                                    ^
                  

                  SyntaxError: 无效语法

                  SyntaxError: invalid syntax

                  推荐答案

                  这个写法,它试图将 CSS 代码解析为 Python 代码.你不想这样.

                  The way this is written, it's trying to parse CSS code as Python code. You don't want that.

                  此功能适用:

                  def frame_switch(css_selector):
                    driver.switch_to.frame(driver.find_element_by_css_selector(css_selector))
                  

                  如果你只是想根据 name 属性切换到框架,那么你可以使用这个:

                  If you are just trying to switch to the frame based on the name attribute, then you can use this:

                  def frame_switch(name):
                    driver.switch_to.frame(driver.find_element_by_name(name))
                  

                  要切换回主窗口,您可以使用

                  To switch back to the main window, you can use

                  driver.switch_to.default_content()
                  

                  这篇关于python, selenium中用于切换帧的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:“NoSuchWindowException:没有这样的窗口:窗口已经关闭"通过 Python3 使用 Sel 下一篇:如何隐藏 Firefox 窗口(Selenium WebDriver)?

                  相关文章

                  <tfoot id='zU4dI'></tfoot>
                1. <small id='zU4dI'></small><noframes id='zU4dI'>

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