Python Selenium (waiting for frame, element lookups)

后端 未结 1 659
清歌不尽
清歌不尽 2020-12-10 20:34

I have these includes:

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys impor         


        
相关标签:
1条回答
  • 2020-12-10 20:59

    You could use WebDriverWait:

    from contextlib import closing
    from selenium.webdriver import Chrome as Browser
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.common.exceptions import NoSuchFrameException
    
    
    def frame_available_cb(frame_reference):
        """Return a callback that checks whether the frame is available."""
        def callback(browser):
            try:
                browser.switch_to_frame(frame_reference)
            except NoSuchFrameException:
                return False
            else:
                return True
        return callback
    
    with closing(Browser()) as browser:
        browser.get(url)
        # wait for frame
        WebDriverWait(browser, timeout=10).until(frame_available_cb("frame name"))
    
    0 讨论(0)
提交回复
热议问题