function for switching frames in python, selenium

后端 未结 1 401
野性不改
野性不改 2020-11-27 07:53

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:<

相关标签:
1条回答
  • 2020-11-27 08:41

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

    This function is suitable:

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

    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()
    
    0 讨论(0)
提交回复
热议问题