selenium处理iframe表单
2021-03-01 本文已影响0人
陈芝麻烂谷子的事
在使用selenium的时候出现一个问题,就是已经定位到这个元素,但是无论怎么都操作不了它,报错内容:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:
出现这个问题极有可能是因为这个元素外面还有一层iframe,需要先进入才能点击
image.png
跳转方式如下:
#首先进入iframe中
driver.switch_to.frame(driver.find_element_by_id('iframe_134328612975012295'))
time.sleep(1)
driver.find_element_by_css_selector("#next").click()
#切出iframe
driver.switch_to.default_content()