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..']"));