selenium 无法切换iframe

<iframe sandbox="allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-same-origin allow-scripts allow-popups" allowfullscreen="true" name="{&quot;hostOrigin&quot;:&quot;https://im.******.com&quot;,&quot;containerId&quot;:1544627686619,&quot;hostVersion&quot;:&quot;3.7.2&quot;,&quot;language&quot;:&quot;zh_CN&quot;}" nwdisable="true" src="https://aflow.******.com/******/pc/query/pchomepage.htm?corpid=******" style="width: 100%; height: 100%; display: inline-block;" cd_frame_id_="ed8be806f350591e756b2762c4c8335e"></iframe>

这个iframe没有id、没有name,请问怎么能切换到这个iframe呢?
已经尝试了:

iframe = browser.find_element_by_xpath('//*[@id="content-pannel"]/div/div[1]/iframe')
browser.switch_to.frame(iframe)

先定位到这个iframe,再切换,但是失败了,并报错:selenium.common.exceptions.WebDriverException: Message: unknown error: call function result missing 'value'

阅读 4.4k
2 个回答
新手上路,请多包涵

你可以换个思路,先等页面加载完,然后获取页面中所有的iframe,通过标签(tags),然后再去找你想要的....

等页面加载完,然后这样试下
driver.switch_to.frame(driver.find_elements_by_tag_name(“iframe”)[0])

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题