2

I am working on an Intranet with nested frames, and am unable to access a child frame.

The HTML source:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
		<title>VIS</title>
		<link rel="shortcut icon" href="https://bbbbb/ma1/imagenes/iconos/favicon.ico">
	</head>
	<frameset rows="51,*" frameborder="no" scrolling="no" border="0">
		<frame id="cabecera" name="cabecera" src="./blablabla.html" scrolling="no" border="3">
			<frameset id="frame2" name="frame2" cols="180,*,0" frameborder="no" border="1">
				<frame id="menu" name="menu" src="./blablabla_files/Menu.html" marginwidth="5" scrolling="auto" frameborder="3">
					<a href="/ma1/jsp/orD/queda.jsp" target="contenido">Buscar</a>
				<frame id="contenido" name="contenido" src="./blablabla_files/saved_resource.html" marginwidth="5" marginheight="5">
					<html>
						<head>
							<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
							<title>BUSCAr</title>
						</head>
						<frameset name="principal" rows="220,*" frameborder="NO">
							 <frame name="Formulario" src="./BusquedaSimple.html" scrolling="AUTO" noresize="noresize">
								<input id="year" name="year" size="4" maxlength="4" value="" onchange="javascript:Orden();" onfocus="this.value='2018';this.select();" type="text">
							 <frame name="Busqueda" src="./saved_resource(2).html" scrolling="AUTO">
						</frameset>
						<noframes>
							&lt;body&gt;
							&lt;p&gt;soporte a tramas.&lt;/p&gt;
							&lt;/body&gt;
						</noframes>
					</html>
				<frame name="frameblank" marginwidth="0" scrolling="no" src="./blablabla_files/saved_resource(1).html">
			</frameset>
			<noframes>
			  &lt;P&gt;Para ver esta página.&lt;/P&gt;
			</noframes>
	</frameset>
</html>

I locate the button "Buscar" inside of frame "menu" with:

driver.switch_to_default_content()
driver.switch_to_frame(driver.find_element_by_css_selector("html frameset frameset#frame2 frame#menu"))
btn_buscar = driver.find_element_by_css_selector("#div_menu > table:nth-child(10) > tbody > tr > td:nth-child(2) > span > a")
btn_buscar.click()

I've tried this code to locate the input id="year" inside frame="Formulario":

driver.switch_to_default_content()
try:       driver.switch_to_frame(driver.switch_to_frame(driver.find_element_by_css_selector("html frameset frameset#frame2 frame#contenido frameset#principal frame#Formulario")))
    print("Ok cabecera -> contenido")
except:
    print("cabecera not found")

or

driver.switch_to_frame(driver.switch_to_xpath("//*[@id='year"]"))

but they don't work.

Can you help me?

Thanks!

1
  • Check provided HTML code sample - it seem to be broken as iframes have no closing tags... Commented Mar 11, 2018 at 15:47

2 Answers 2

1

To be able to handle required iframe you need to switch subsequently to all ancestor frames:

driver.switch_to.frame("cabecera")
driver.switch_to.frame("menu")
btn_buscar = driver.find_element_by_link_text("Buscar")
btn_buscar.click()

Also note that Webdriver instance has no such method as switch_to_xpath() and switch_to_frame(), switch_to_default_content() methods are deprecated so you'd better use switch_to.frame(), switch_to.default_content()

Sign up to request clarification or add additional context in comments.

Comments

0

Assuming your program have the focus on Top Level Browsing Context, to locate and the button with text as Buscar you need to switch() through all the parent frames along with WebDriverWait in association with proper expected_conditions and you can use the following code block :

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(By.ID,"cabecera"))
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(By.ID,"menu"))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Buscar"))).click()

1 Comment

I tried both options, but it was impossible to arrive to "Buscar" button inside the "menu" frame. Finally, I decided load the <frame id="contenido" name="contenido" src="./blablabla_files/saved_resource.html" marginwidth="5" marginheight="5"> that loads the same result of "Buscar" button, because it is the frame that loads the form and the only part that I need. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.