Home > Blockchain >  Frameset indeed in frame problem PYTHON SELENIUM
Frameset indeed in frame problem PYTHON SELENIUM

Time:11-07

I want to go inside frame name "body", but it isnt work. I can go to first frame and everything works, but problem is when I try to go inside indeed frameset. Selenium cant see it

This is my code:

frame = driver.find_element(By.XPATH, "/html/frameset/frame[2]")
driver.switch_to.frame(frame)
frame= driver.find_element(By.XPATH, '/html/frameset/frame[1]')
driver.switch_to.frame(frame)

HTML CODE:

<html><head>
      <title>
         Le Moniteur belge.
      </title> 
</head>
    <frameset rows="14%,*">
    <frame src="rech_f1.htm" name="frame1_fr" noresize="">
    <frame src="rech_f2.htm" name="frame2_fr" cd_frame_id_="f1e39289d55588245ed84ea909665732">
    <html>
    <frameset>
     <frame src="list_body.pl?language=fr&amp;sql=htit contains  'roche'&amp;fromtab= moftxt UNION montxt UNION modtxt&amp;rech=83&amp;trier=promulgation&amp;tri=dd AS RANK &amp;dt=&amp;ddda=&amp;dddm=&amp;dddj=&amp;ddfa=&amp;ddfm=&amp;ddfj=&amp;pdda=&amp;pddm=&amp;pddj=&amp;pdfa=&amp;pdfm=&amp;pdfj=&amp;numac=&amp;bron=&amp;htit=roche&amp;text1=&amp;choix1=ET&amp;text2=&amp;choix2=ET&amp;text3=&amp;exp=&amp;&amp;fr=f&amp;nl=n&amp;du=d&amp;an=" name="Body" scrolling="auto">
        </frameset>
       </html>

    <noframes>
    pas de frames
    </noframes>
    </frameset>

CodePudding user response:

I guess the second iframe is not inside the first iframe.
If so, after going into the first iframe you need to get back to the default content and only after that to switch to the second iframe, as following:

frame = driver.find_element(By.XPATH, "/html/frameset/frame[2]")
driver.switch_to.frame(frame)
driver.switch_to.default_content()
frame= driver.find_element(By.XPATH, '/html/frameset/frame[1]')
driver.switch_to.frame(frame)

CodePudding user response:

Looks like the frame body is in the second frameset which is inside the first frameset. So you can find it using full xpath: (By.XPATH, "/html/frameset/frameset/frame")
Or you can try to find it using this realtive XPATH (By.XPATH, "//frame[@name='Body']")]

  • Related