1

我有一個Chrome擴展,我想用Selenium來測試它。擴展名將iframe標記放置到頁面上。Selenium:Chrome擴展的NoSuchFrameException

我可以通過運行以下命令順利拿到iframe標籤:

top_frame = driver.find_element(By.XPATH, value='//iframe[@class="top-frame"]') 

然而,當我嘗試切換到幀我得到「NoSuchFrameException」的錯誤。

driver.switch_to.frame(top_frame) 

下面一行輸出幀的類名正確

print(top_frame.get_attribute('class')) 

錯誤日誌:

Testing http://www.google.com 

Traceback (most recent call last): 
    File "test/run_tests.py", line 200, in <module> 
    main() 
    File "test/run_tests.py", line 197, in main 
    run_tests(args.plugin, args.out, args.url) 
    File "test/run_tests.py", line 167, in run_tests 
    button = check_button(driver, url) 
    File "test/run_tests.py", line 84, in check_button 
    driver.switch_to.frame(top_frame) 
    File "/home/burak/.virtualenv/extension/lib/python3.5/site-packages/selenium/webdriver/remote/switch_to.py", line 87, in frame 
    self._driver.execute(Command.SWITCH_TO_FRAME, {'id': frame_reference}) 
    File "/home/burak/.virtualenv/extension/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute 
    self.error_handler.check_response(response) 
    File "/home/burak/.virtualenv/extension/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response 
    raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.NoSuchFrameException: Message: no such frame: element is not a frame 
    (Session info: chrome=60.0.3112.90) 
    (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Linux 4.10.0-30-generic x86_64) 
+0

幀可能沒有被初始化。因爲瀏覽器可能會阻止框架本身? –

+0

然而,我可以得到框架。我認爲幀的初始化不是問題。 –

+0

你目前是否比提到的框架有其他框架? – Kapil

回答

0

在最新的Chrome版本,最有可能有一個BU g打破了switch_to_frame()調用。因此,我開始使用Firefox,現在一切都很順利。

0

試試這個男人,

driver.switch_to.frame(driver.find_element(By.XPATH,value=".//iframe[@src='give your frame source name here..']"));