How to access frame with python selenium

我只是一个虾纸丫 提交于 2020-12-13 11:59:46

问题


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>

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>

which outputs:

frame1
frame1b
frame4
frame6
frame8
frame2

frame3

cancelFrame

frame5


frame6

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?


回答1:


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


来源:https://stackoverflow.com/questions/37061765/how-to-access-frame-with-python-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!