title: Execute script in web browser (python - selenium)
body: <p>within a web page is a script that allows you to see a video and other.</p>
  
  <p>using python and selenium can not be run the script after the mouse clicks. Of the currently am using this code:</p>
  
  <pre><code>videoGemPath        = ".//*[@id='brandconnect']/a/img"
      scriptPath      = ".//*[@id='content']/script"
      elementScript   = "/html/body/div[2]/div[1]"
      location        = driver.find_element_by_xpath(scriptPath)
      ActionChains(driver).move_to_element(location).click().perform()
  </code></pre>
  
  <p>but it returns this error</p>
  
  <p>=========================================================================
  Traceback (most recent call last):
    File "C:\Users\xxxxxx\Desktop\Proggetti VB\Per Web\PythonApplication4\PythonApplication4\PythonApplication4.py", line 66, in test_Login
      ActionChains(driver).move_to_element(location).click().perform()
    File "C:\Python27\lib\site-packages\selenium-2.48.0-py2.7.egg\selenium\webdriver\common\action_chains.py", line 72, in perform
      action()
    File "C:\Python27\lib\site-packages\selenium-2.48.0-py2.7.egg\selenium\webdriver\common\action_chains.py", line 217, in 
      self._driver.execute(Command.MOVE_TO, {'element': to_element.id}))
    File "C:\Python27\lib\site-packages\selenium-2.48.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 201, in execute
      self.error_handler.check_response(response)
    File "C:\Python27\lib\site-packages\selenium-2.48.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 181, in check_response
      raise exception_class(message, screen, stacktrace)
  MoveTargetOutOfBoundsException: Message: Offset within element cannot be scrolled into view: (352.5, 241.5): [object HTMLScriptElement]
  Stacktrace:
      at FirefoxDriver.prototype.mouseMoveTo (file:///c:/users/xxxxxx/appdata/local/temp/tmpgnvb0k/extensions/fxdriver@googlecode.com/components/driver-component.js:10961)
      at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/xxxxxx/appdata/local/temp/tmpgnvb0k/extensions/fxdriver@googlecode.com/components/command-processor.js:12534)
      at DelayedCommand.prototype.executeInternal_ (file:///c:/users/xxxxxx/appdata/local/temp/tmpgnvb0k/extensions/fxdriver@googlecode.com/components/command-processor.js:12539)
      at DelayedCommand.prototype.execute/&lt; (file:///c:/users/xxxxxxx/appdata/local/temp/tmpgnvb0k/extensions/fxdriver@googlecode.com/components/command-processor.js:12481)</p>
  
  <p>=========================================================================</p>
  
  <p>the script code is this:</p>
  
  <pre><code>            // create button
          document.write('&lt;div id="brandconnect"&gt;&lt;a href="javascript:SSA_CORE.BrandConnect.engage();" onmouseover="hoverBC();" onmouseout="unhoverBC();"&gt;&lt;img src="img/bconnect_area.png" class="tooltip" rel="Guarda video e ricevi Gemme gratis!" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;');
  
          // ini local storage to save last button state if this html5 feature is available
          var storage = false;
          try {
              if( window &amp;&amp; window.localStorage ) {
                  storage = window.localStorage;
                  if( typeof(storage.bcVisible) === 'string' ) {
                      if( storage.bcVisible == 'true' ) {
                          showBC();
                      }
                      else {
                          hideBC();
                      }
                  }
              }
          }
          catch( ignore ) {
              // local storage might require user approval. in this case we don't use it
          }
  
          // handle button visibility
          function handleBC(obj) {
              if( typeof(obj) != 'object' || obj.length &lt; 1 ) {
                  // no videos available
                  hideBC();
              }
              else {
                  // videos are available
                  showBC();
              }
          }
  
          // show brandconnect button
          function showBC() {
              clink = document.getElementById('brandconnect');
              if( clink ) {
                  clink.style.display = 'block';
              }
              if( storage ) {
                  storage.bcVisible = 'true';
              }
          }
  
          // hide brandconnect button
          function hideBC() {
              document.getElementById('brandconnect').style.display = 'none';
              if( storage ) {
                  storage.bcVisible = 'false';
              }
          }
  
          function hoverBC() {
              document.getElementById('brandconnect').style.backgroundPosition = '-89px 0';
          }
  
          function unhoverBC() {
              document.getElementById('brandconnect').style.backgroundPosition = '0 0';
          }
  
          // definitions by JSON
          var ssa_json = {
              'applicationUserId': '512000516',
              'applicationKey': '2ae25b1d',
              'currencyName': 'Gemme',
              'onCampaignsReady': handleBC,
              'onCampaignsDone': hideBC,
              'onCampaignCompleted': handleBC,
              'onCampaignClose': handleBC
          };
  
          // embed supersonic script
          (function(d,t){
          var g = d.createElement(t), s = d.getElementsByTagName(t)[0]; g.async = true;
          g.src = ('https:' != location.protocol ? 'http://jsd.supersonicads.com' :
          'https://supersonicads.cotssl.net') + '/inlineDelivery/delivery.min.gz.js';
          s.parentNode.insertBefore(g,s);
          }(document,'script'));
          //]]&gt;
  </code></pre>
  
  <p>How can I fix it?</p>