I am trying to select an option from the webpage below using Selenium-Python. I inspected the element and got xpath and css selector. However, no matter what I tried, I still couldn't find the element so I could click on it and move on. I did some research and guessed that it belongs to an iframe. I still can't switch to iframe using the css selector.
So far I have tried to find the element by css selector and XPATH. Both have failed.
driver.find_element_by_css_selector('#bootstrap-content > div.ng-scope > div > div:nth-child(2) > div.container-fluid > div > cms-block > div > div > div > div > cms-block > div > div > div.col-xs-12.col-sm-12 > div.node-box > div > div > cms-block > div > div:nth-child(1) > div > ces-inquiry-matching > div > div.segment-box.node-content-box > div:nth-child(3) > div > div > form > label:nth-child(1)') driver.find_element_by_xpath('//*[@id="bootstrap-content"]/div[2]/div/div[2]/div[3]/div/cms-block/div/div/div/div/cms-block/div/div/div[2]/div[2]/div/div/cms-block/div/div[1]/div/ces-inquiry-matching/div/div[1]/div[2]/div/div/form/label[1]')
I tried to switch to frame. Still failed.
frame = driver.find_element_by_css_selector('#bootstrap-content > div.ng-scope > div > div:nth-child(2) > div.container-fluid > div > cms-block > div > div > div > div > cms-block > div > div > div.col-xs-12.col-sm-12 > div.node-box > div > div > cms-block > div > div:nth-child(1) > div > ces-inquiry-matching > div > div.segment-box.node-content-box > div:nth-child(2) > div > div > form > label:nth-child(1)') driver.switch_to.frame(frame)
Here's the HTML of the page:
<!DOCTYPE html> <html disable-right-click lang=en> <!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"><![endif]--> <!--[if IE 7]><html class="no-js lt-ie9 lt-ie8"><![endif]--> <!--[if IE 8]><html class="no-js lt-ie9"><![endif]--> <!--[if gt IE 8]><!--><html class=no-js><!--<![endif]--> <head> <meta charset=utf-8> <meta http-equiv=X-UA-Compatible content="IE=edge"> <title ng-bind=pageTitle>LEAP</title> <meta name=description content=""> <meta name=viewport content="width=device-width,initial-scale=1"> <!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-PLRJK9R');</script> <!-- End Google Tag Manager --> <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> <link rel=stylesheet href=assets/styles/267a61ef.vendor.css> <link rel=stylesheet href=assets/styles/a355f906.main.css> <link rel=stylesheet href=bower_components/img-viewerjs/dist/viewer.min.css /> <link type=text/css href=vendor/jplayer/skin/blue.monday/css/jplayer.blue.monday.css rel=stylesheet /> <style> @media print { .hidden-print { display: none !important; } } </style> </head> <body tabindex=-1 class="common-app main-app" onload=bootstrap()> <!-- Google Tag Manager (noscript) --> <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-PLRJK9R" height=0 width=0 style=display:none;visibility:hidden></iframe></noscript> <!-- End Google Tag Manager (noscript) --> <div id=bootstrap-content class=hidden ng-class="{'app-visible': initialPageLoaded}"> <!--[if lt IE 9]> <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> <![endif]--> <div has-authority=ROLE_PREVIOUS_ADMINISTRATOR class=impersonate-user-container> Impersonating... <a class="btn btn-default btn-xs" href=admin/impersonate/stop>Stop</a> </div> <div ui-view=content-container></div> </div> <div id=bootstrap-loading class=bootstrap-message> <div id=bootstrap-loading-message class=hidden> <i class="fa fa-circle-o-notch fa-spin"></i> Loading application.... </div> </div> <div id=bootstrap-error class="bootstrap-message hidden"> Error loading application... Please try refreshing the page. </div> <form id=legacyLeapLoginForm name=legacyLeapLoginForm method=post> <input type=hidden name=j_username> <input type=hidden name=j_password> <input type=hidden name=ces_token> <input type=hidden name=product_id> <input type=hidden name=ui_switch> </form> <script type=text/javascript> function bootstrap() { angular.lazy('app.apps.main-app') .resolve(function ($http) { var postData = {}; return $http.post('api/system/bootstrap/config', postData).then( function success(response) { appGlobal.config.setAll(response.data); } ); }) .error(function() { angular.element('#bootstrap-loading').addClass('hidden'); angular.element('#bootstrap-error').removeClass('hidden'); }) .done(function() { angular.element('#bootstrap-loading').addClass('hidden'); angular.element('#bootstrap-content').removeClass('hidden'); }) .bootstrap(); setTimeout(function() { angular.element('#bootstrap-loading-message').removeClass('hidden'); }, 300); } </script> <script src=scripts/9cbb9f87.vendor.js></script> <script src=scripts/acabc07f.app.js></script> <script src=vendor/jplayer/jplayer/jquery.jplayer.js></script> <script src=assets/js/typingdna/typingdna.js></script> <script src=bower_components/img-viewerjs/dist/viewer.min.js></script> <script src=bower_components/ng-resize/dist/ng-resize.js></script> </body> </html> </html>