zmatilsky901
zmatilsky901

Reputation: 11

How to access frame with python selenium

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?

Upvotes: 1

Views: 884

Answers (1)

Andersson
Andersson

Reputation: 52665

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

Upvotes: 1

Related Questions