如何使用 python selenium 访问框架 [英] How to access frame with python selenium

查看:31
本文介绍了如何使用 python selenium 访问框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我认为包含在框架内的 html 页面上填写表单.html 的相关部分如下所示:

I am trying to fill a form on an html page that I believe is contained within a frame. The relevant portion of the html looks like this:

<frameset rows="*" cols="*,183" frameborder="NO" border="0" framespacing="0">
<frameset rows="61,28,*,0,0" cols="*" frameborder="NO" border="0" framespacing="0">
<frame src="fr1_tab1.jhtml?NUM1=1462489510565" scrolling="NO" noresize name="frame1" title="page header - navigation">
<frame src="fr4_top.jhtml?NUM1=1462489510565" scrolling="NO" noresize name="frame1b" title="page header - search">
<frame name="frame4" title="main body" src="processShowMyPeapodPage2.jhtml?NUM1=1462489510565" noresize scrolling="AUTO">
<frame src="frame6.jhtml" marginwidth="0" marginheight="0" name="frame6" noresize frameborder="NO" border="0" title="empty">
<frame src="frame8.jhtml" marginwidth="0" marginheight="0" name="frame8" noresize frameborder="NO" border="0" title="empty">
</frameset>

我要找的相关信息在frame1b里面.使用 Selenium,我已经确认 frame1b 确实位于页面上:

The relevant information that I am looking for is located inside of frame1b. Using Selenium, I've confirmed that frame1b is indeed located on the page:

<code>
for thing in driver.find_elements_by_tag_name('frame'):
    print thing.get_attribute('name')
</code>

输出:

frame1
frame1b
frame4
frame6
frame8
frame2

frame3

cancelFrame

frame5


frame6

所以在这一切之后,我尝试使用 driver.switch_to_frame('frame1b'),但我收到错误 NoSuchFrameException: Message: no such frame.

So after all of this, I try to use driver.switch_to_frame('frame1b'), but I get the error NoSuchFrameException: Message: no such frame.

我的问题是,我怎样才能进入这个框架,或者如果没有必要进入这个框架来访问其中的一个表单,我如何直接访问该表单?

My question is, how can I get into this frame, or if it is not necessary to get into this frame to access one of it's forms, how can I directly access the form?

推荐答案

我可能是错误的,但据我所知,只有选择器是一个元素,才能使用 driver.sto_frame(选择器)代码>id.在您的情况下,请尝试使用以下内容:

I could be wrong but as far as I know you can use driver.switch_to_frame(selector) only if selector is an element id. In your case try to use following:

driver.switch_to_frame(driver.find_element_by_xpath('//frame[@src="fr4_top.jhtml?NUM1=1462489510565"]'))

这篇关于如何使用 python selenium 访问框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆