title: how to click iframe using python selenium
body: <p>I want to click an iframe's radio button, but it doesn't work.
  my code is this.</p>
  
  <pre><code>import time
  from selenium import webdriver
  Url='https://www.youtube.com/watch?v=eIStvhR347g'
  driver = webdriver.Firefox()
  driver.get('https://video-download.online')
  driver.find_element_by_id("link").send_keys(Url)
  driver.find_element_by_id("submit").click()
  time.sleep(5)
  
  #this part is problems... don't working
  driver.switch_to_frame(driver.find_element_by_tag_name("iframe"))
  driver.find_element_by_css_selector("136-wrapper").click()
  driver.find_element_by_link_text("Proceed").click()
  </code></pre>
  
  <p>html source is this.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"/&gt;
  &lt;script&gt;
          if (top.location !== location) {
              top.location = self.location;
          }
          if (location.host !== 'video-download.online' &amp;&amp; location.host !== 'beta.video-download.online') {
              eval("location.href=''+'//'+'video-download.online';");
          }
      &lt;/script&gt;
  &lt;meta name="msapplication-tap-highlight" content="no"/&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/&gt;
  &lt;meta name="author" content="Luca Steeb"/&gt;
  &lt;meta name="theme-color" content="#008679"/&gt;
  &lt;meta name="description" content="Download from this uploaded.net premium link generator with highspeed. For free."/&gt;
  &lt;meta property="og:title" content="Video-Download.online"/&gt;
  &lt;meta property="og:description" content="Download videos, mp3s and playlists from 1979 sites - for free."/&gt;
  &lt;meta property="og:type" content="website"/&gt;
  &lt;meta property="og:url" content="video-download.online"/&gt;
  &lt;meta property="fb:page_id" content="1143492155680932"/&gt;
  &lt;meta property="og:image" content="//video-download.online/img/logo.jpg"/&gt;
  &lt;link rel="shortcut icon" href="/favicon.ico?1"/&gt;
  &lt;link rel="icon" sizes="192x192" href="/img/logo_small.jpg"/&gt;
  &lt;link rel="apple-touch-icon" href="/img/apple-touch-icon.png"/&gt;
  &lt;link rel="search" type="application/opensearchdescription+xml" title="Video-Download.online" href="/opensearch.xml"/&gt;
  &lt;title&gt;
  Online Video Download
  &lt;/title&gt;
  &lt;meta name="robots" content="noindex, nofollow"/&gt;
  &lt;link rel="stylesheet" href="/css/bt.css"/&gt;
  &lt;link rel="stylesheet" href="/css/style.css"/&gt;
  &lt;noscript&gt;&lt;iframe height=0 src="//www.googletagmanager.com/ns.html?id=GTM-TWMNRP"style=display:none;visibility:hidden width=0&gt;&lt;/iframe&gt;&lt;/noscript&gt;&lt;script&gt;!function(e,t,a,n,r){e[n]=e[n]||[],e[n].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var g=t.getElementsByTagName(a)[0],m=t.createElement(a),s="dataLayer"!=n?"&amp;l="+n:"";m.async=!0,m.src="//www.googletagmanager.com/gtm.js?id="+r+s,g.parentNode.insertBefore(m,g)}(window,document,"script","dataLayer","GTM-TWMNRP")&lt;/script&gt;
  
      &lt;script&gt;(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create','UA-54289597-5','auto');ga('send','pageview');&lt;/script&gt;   
  
      &lt;script&gt;function send(action) { ga('send', 'event', 'button', 'click', 'download-' + action) }&lt;/script&gt;
      &lt;script async src="/js/jquery.js"&gt;&lt;/script&gt;
      &lt;script&gt;function _(n,i){i?window[n]?i():setTimeout(function(){_(n,i)},100):window.jQuery?window.jQuery(document).ready(function(){n(window.jQuery)}):setTimeout(function(){_(n)},100)}&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
      &lt;header class="navbar navbar-info navbar-fixed-top"&gt;
          &lt;div class="container"&gt;
              &lt;div class="navbar-header"&gt;
                  &lt;button type="button" class="navbar-toggle no-waves" data-toggle="collapse" data-target=".navbar-collapse"&gt;
                      &lt;span class="icon-bar"&gt;&lt;/span&gt;
                      &lt;span class="icon-bar"&gt;&lt;/span&gt;
                      &lt;span class="icon-bar"&gt;&lt;/span&gt;
                  &lt;/button&gt;
  
                  &lt;div class="nav-brand"&gt;
                      &lt;a class="navbar-brand" href="/"&gt;
                          &lt;img class="logo" src="/img/logo.svg" alt=""/&gt;
  
                          &lt;div class="parent"&gt;
  
                                  Video-Download&lt;small&gt;.online&lt;/small&gt;
                                  &lt;br/&gt;
                                  &lt;span class="small-text"&gt;1979 sites officially supported&lt;/span&gt;
  
                              &lt;span id="changelog"&gt;&lt;/span&gt;
                          &lt;/div&gt;
  
                          &lt;span class="clear"&gt;&lt;/span&gt;
                      &lt;/a&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="navbar-collapse collapse"&gt;
              &lt;ul class="nav navbar-nav navbar-right"&gt;
                  &lt;div class="social"&gt;
                      &lt;div class="fb-like fb-nav" data-href="https://www.facebook.com/VideoDownload.online"
                           data-layout="button_count" data-action="like" data-show-faces="false" data-share="true"&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="social-close" title="Hide all social buttons"&gt;&amp;times;&lt;/div&gt;
  
                  &lt;li class=" "&gt;
  &lt;a href="/"&gt;
      Home
  &lt;/a&gt;
  &lt;/li&gt;
                  &lt;li class=" "&gt;
  &lt;a href="/sites"&gt;
      Sites
  &lt;/a&gt;
  &lt;/li&gt;
                  &lt;li class=" "&gt;
  &lt;a href="/contact"&gt;
      Contact
  &lt;/a&gt;
  &lt;/li&gt;
                  &lt;!--html.navItem('/app', 'Mobile App')--&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/header&gt;
  
  &lt;noscript class="fixed"&gt;
      &lt;div class="container"&gt;Please enable javascript. Video Download and almost all other sites don't work properly
          without it.
      &lt;/div&gt;
  &lt;/noscript&gt;
  
  &lt;div id="alert" class="alert alert-fixed alert-dismissible m-t-15 hidden"&gt;
      &lt;div class="container relative"&gt;
          &lt;span id="alertText"&gt;&lt;/span&gt;
          &lt;span class="close-alert" onclick="_(function() { $('#alert').remove();$('body').removeClass('alert-showing') })" title="close"&gt;×&lt;/span&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;main class="container"&gt;
      &lt;div&gt;
      &lt;h1&gt;Legal&lt;/h1&gt;
  
      &lt;div style="width: 50%;" class="center"&gt;
  
      &lt;/div&gt;
  &lt;/main&gt;
  
  &lt;script src="/sweetalert/sweetalert.js"&gt;&lt;/script&gt;
  &lt;link rel="stylesheet" href="/sweetalert/sweetalert.css"&gt;  
  
  &lt;script src="/waves/waves.min.js"&gt;&lt;/script&gt;
  &lt;script src="/js/dropdown.js"&gt;&lt;/script&gt;
  &lt;script src="/js/main.js"&gt;&lt;/script&gt;
  &lt;script src="/js/bootstrap.js"&gt;&lt;/script&gt;   
  
  &lt;script type="text/javascript"&gt;/* &lt;![CDATA[ */(function(d,s,a,i,j,r,l,m,t){try{l=d.getElementsByTagName('a');t=d.createElement('textarea');for(i=0;l.length-i;i++){try{a=l[i].href;s=a.indexOf('/cdn-cgi/l/email-protection');m=a.length;if(a&amp;&amp;s&gt;-1&amp;&amp;m&gt;28){j=28+s;s='';if(j&lt;m){r='0x'+a.substr(j,2)|0;for(j+=2;j&lt;m&amp;&amp;a.charAt(j)!='X';j+=2)s+='%'+('0'+('0x'+a.substr(j,2)^r).toString(16)).slice(-2);j++;s=decodeURIComponent(s)+a.substr(j,m-j)}t.innerHTML=s.replace(/&lt;/g,'&amp;lt;').replace(/&gt;/g,'&amp;gt;');l[i].href='mailto:'+t.value}}catch(e){}}}catch(e){}})(document);/* ]]&gt; */&lt;/script&gt;&lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>frame source is this.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"/&gt;
  &lt;meta name="robots" content="noindex, nofollow"/&gt;
  &lt;link rel="stylesheet" href="/css/bt.css"/&gt;
  &lt;link rel="stylesheet" href="/css/style.css"/&gt;
  &lt;script src="/js/jquery.js"&gt;&lt;/script&gt;
  &lt;style&gt;body{margin:0!important;}tr{clear:both;cursor:pointer;}td{padding:0 20px 0 0;white-space:nowrap;}.radio{margin-top:5px;margin-bottom:5px;}.small{padding:0;font-size:85%;}@media (max-width: 319px) {table{font-size:12px;}}@media (max-width: 480px) {td{padding:0 5px 0 0;}.small{font-size:50%;}}&lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form id="format" method="post"&gt;
  &lt;input name="id" type="hidden" value="isxklqy5blw9of7"/&gt;
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td class="small"&gt;
  &lt;div class=""&gt;
  &lt;div class="radio " id="undefined-wrapper"&gt;
  &lt;label class="text-capitalize" for="undefined"&gt;
  &lt;input id="undefined" name="format" type="radio" value="undefined" onchange="" undefined required /&gt;
  &lt;span class=circle&gt;&lt;/span&gt;&lt;span class=check&gt;&lt;/span&gt;
  &lt;span class="grey-text"&gt;&lt;/span&gt;
  &lt;/label&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/td&gt;
  &lt;td&gt;I don't care&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td class="small"&gt;
  &lt;div class=""&gt;
  &lt;div class="radio " id="160-wrapper"&gt;
  &lt;label class="text-capitalize" for="160"&gt;
  &lt;input id="160" name="format" type="radio" value="160" onchange="" undefined required /&gt;
  &lt;span class=circle&gt;&lt;/span&gt;&lt;span class=check&gt;&lt;/span&gt;
  &lt;span class="grey-text"&gt;&lt;/span&gt;
  &lt;/label&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/td&gt;
  &lt;td&gt;256x144&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt;
  30 FPS
  &lt;/td&gt;
  &lt;td&gt;23.2 MB&lt;/td&gt;
  &lt;/tr&gt;&lt;tr&gt;
  &lt;td class="small"&gt;
  &lt;div class=""&gt;
  &lt;div class="radio " id="133-wrapper"&gt;
  &lt;label class="text-capitalize" for="133"&gt;
  &lt;input id="133" name="format" type="radio" value="133" onchange="" undefined required /&gt;
  &lt;span class=circle&gt;&lt;/span&gt;&lt;span class=check&gt;&lt;/span&gt;
  &lt;span class="grey-text"&gt;&lt;/span&gt;
  &lt;/label&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/td&gt;
  &lt;td&gt;426x240&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt;
  30 FPS
  &lt;/td&gt;
  &lt;td&gt;51.2 MB&lt;/td&gt;
  &lt;/tr&gt;&lt;tr&gt;
  &lt;td class="small"&gt;
  &lt;div class=""&gt;
  &lt;div class="radio " id="134-wrapper"&gt;
  &lt;label class="text-capitalize" for="134"&gt;
  &lt;input id="134" name="format" type="radio" value="134" onchange="" undefined required /&gt;
  &lt;span class=circle&gt;&lt;/span&gt;&lt;span class=check&gt;&lt;/span&gt;
  &lt;span class="grey-text"&gt;&lt;/span&gt;
  &lt;/label&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/td&gt;
  &lt;td&gt;640x360&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt;
  30 FPS
  &lt;/td&gt;
  &lt;td&gt;65.4 MB&lt;/td&gt;
  &lt;/tr&gt;&lt;tr&gt;
  &lt;td class="small"&gt;
  &lt;div class=""&gt;
  &lt;div class="radio " id="135-wrapper"&gt;
  &lt;label class="text-capitalize" for="135"&gt;
  &lt;input id="135" name="format" type="radio" value="135" onchange="" undefined required /&gt;
  &lt;span class=circle&gt;&lt;/span&gt;&lt;span class=check&gt;&lt;/span&gt;
  &lt;span class="grey-text"&gt;&lt;/span&gt;
  &lt;/label&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/td&gt;
  &lt;td&gt;854x480&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt;
  30 FPS
  &lt;/td&gt;
  &lt;td&gt;138.0 MB&lt;/td&gt;
  &lt;/tr&gt;&lt;tr&gt;
  &lt;td class="small"&gt;
  &lt;div class=""&gt;
  &lt;div class="radio " id="136-wrapper"&gt;
  &lt;label class="text-capitalize" for="136"&gt;
  &lt;input id="136" name="format" type="radio" value="136" onchange="" undefined required /&gt;
  &lt;span class=circle&gt;&lt;/span&gt;&lt;span class=check&gt;&lt;/span&gt;
  &lt;span class="grey-text"&gt;&lt;/span&gt;
  &lt;/label&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/td&gt;
  &lt;td&gt;1280x720&lt;/td&gt;
  &lt;td&gt;HD&lt;/td&gt;
  &lt;td&gt;
  30 FPS
  &lt;/td&gt;
  &lt;td&gt;272.2 MB&lt;/td&gt;
  &lt;/tr&gt;&lt;tr&gt;
  &lt;td class="small"&gt;
  &lt;div class=""&gt;
  &lt;div class="radio " id="298-wrapper"&gt;
  &lt;label class="text-capitalize" for="298"&gt;
  &lt;input id="298" name="format" type="radio" value="298" onchange="" undefined required /&gt;
  &lt;span class=circle&gt;&lt;/span&gt;&lt;span class=check&gt;&lt;/span&gt;
  &lt;span class="grey-text"&gt;&lt;/span&gt;
  &lt;/label&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/td&gt;
  &lt;td&gt;1280x720&lt;/td&gt;
  &lt;td&gt;HD&lt;/td&gt;
  &lt;td&gt;
  60 FPS
  &lt;/td&gt;
  &lt;td&gt;385.0 MB&lt;/td&gt;
  &lt;/tr&gt;&lt;tr&gt;
  &lt;td class="small"&gt;
  &lt;div class=""&gt;
  &lt;div class="radio " id="137-wrapper"&gt;
  &lt;label class="text-capitalize" for="137"&gt;
  &lt;input id="137" name="format" type="radio" value="137" onchange="" undefined required /&gt;
  &lt;span class=circle&gt;&lt;/span&gt;&lt;span class=check&gt;&lt;/span&gt;
  &lt;span class="grey-text"&gt;&lt;/span&gt;
  &lt;/label&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/td&gt;
  &lt;td&gt;1920x1080&lt;/td&gt;
  &lt;td&gt;Full HD&lt;/td&gt;
  &lt;td&gt;
  30 FPS
  &lt;/td&gt;
  &lt;td&gt;535.0 MB&lt;/td&gt;
  &lt;/tr&gt;&lt;tr&gt;
  &lt;td class="small"&gt;
  &lt;div class=""&gt;
  &lt;div class="radio " id="299-wrapper"&gt;
  &lt;label class="text-capitalize" for="299"&gt;
  &lt;input id="299" name="format" type="radio" value="299" onchange="" undefined required /&gt;
  &lt;span class=circle&gt;&lt;/span&gt;&lt;span class=check&gt;&lt;/span&gt;
  &lt;span class="grey-text"&gt;&lt;/span&gt;
  &lt;/label&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/td&gt;
  &lt;td&gt;1920x1080&lt;/td&gt;
  &lt;td&gt;Full HD&lt;/td&gt;
  &lt;td&gt;
  60 FPS
  &lt;/td&gt;
  &lt;td&gt;707.0 MB&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;button class="btn center" type="submit"&gt;Proceed &amp;raquo;&lt;/button&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;script&gt;
      $('tr').click(function() {
          $(this).find('input').prop('checked', true);
      });
  &lt;/script&gt;
  &lt;script src="/waves/waves.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      Waves.attach('.btn', ['waves-light']);
      Waves.init();
  &lt;/script&gt;
  </code></pre>
  
  <p>I tried these codes, but don't work.</p>
  
  <pre><code>driver.switch_to_frame(driver.find_element_by_xpath('//iframe[contains(@name, "frame")]'))
  driver.switch_to_frame(driver.find_element_by_tag_name("iframe"))
  driver.switch_to_frame(driver.find_element_by_xpath('//iframe'))
  driver.switch_to_frame(0)
  </code></pre>
  
  <p>these iframe switching codes are any exception is nothing, but result is '[]'.</p>
  
  <pre><code>&gt;&gt;&gt; driver.switch_to_frame(driver.find_element_by_xpath('//iframe'))
  &gt;&gt;&gt; driver.find_elements_by_xpath("//*[@type='radio']")
  []
  &gt;&gt;&gt; driver.find_elements_by_xpath("//*[@type='radio']")[0].click()
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  IndexError: list index out of range
  </code></pre>
  
  <p>thanks for your help</p>