使用Python/Selenium切换iframe [英] Switching iframes with Python/Selenium
本文介绍了使用Python/Selenium切换iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用selenium
导航使用框架的网站.
I am attempting to use selenium
to navigate a website that is using frames.
这是我在第1部分工作的python脚本:
Here is my working python script for part 1:
from selenium import webdriver
import time
from urllib import request
driver = webdriver.Firefox()
driver.get('http://www.lgs-hosted.com/rmtelldck.html')
driver.switch_to.frame('menu')
driver.execute_script('xSubmit()')
time.sleep(.5)
link = driver.find_element_by_id('ml1T2')
link.click()
这是页面元素:
<html webdriver="true">
<head></head>
<frameset id="menuframe" name="menuframe" border="0" frameborder="0" cols="170,*">
<frameset border="0" frameborder="0" rows="0,*">
<frame scrolling="AUTO" noresize="" frameborder="NO" src="heart.html" name="heart"></frame>
<frame scrolling="AUTO" noresize="" frameborder="NO" src="rmtelldcklogin.html" name="menu"></frame>
</frameset>
<frame scrolling="AUTO" noresize="" frameborder="NO" src="rmtelldcklogo.html" name="update"></frame>
</frameset>
</html>
我的问题是切换帧...在菜单"中,我需要进入更新":
My issue is switching the frames...its in 'menu' I need to get into 'update':
driver.switch_to.frame('update')
^不起作用....错误告诉我它不存在,即使我们可以清楚地看到它是...任何想法?
^ does not work....error tells me its not there, even though we can clearly see it is...any ideas?
如何从menu
切换到update
?
推荐答案
在切换到其他框架之前,您需要切换回默认内容:
You need to switch back to the default content before switching to a different frame:
driver.switch_to.default_content()
driver.switch_to.frame("update")
# to prove it is working
title = driver.find_element_by_id("L_DOCTITLE").text
print(title)
打印:
Civil Case Inquiry
这篇关于使用Python/Selenium切换iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文