Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

within a web page is a script that allows you to see a video and other.

using python and selenium can not be run the script after the mouse clicks. Of the currently am using this 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()

but it returns this error

========================================================================= 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/[email protected]/components/driver-component.js:10961) at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/xxxxxx/appdata/local/temp/tmpgnvb0k/extensions/[email protected]/components/command-processor.js:12534) at DelayedCommand.prototype.executeInternal_ (file:///c:/users/xxxxxx/appdata/local/temp/tmpgnvb0k/extensions/[email protected]/components/command-processor.js:12539) at DelayedCommand.prototype.execute/< (file:///c:/users/xxxxxxx/appdata/local/temp/tmpgnvb0k/extensions/[email protected]/components/command-processor.js:12481)

=========================================================================

the script code is this:

            // create button
        document.write('<div id="brandconnect"><a href="javascript:SSA_CORE.BrandConnect.engage();" onmouseover="hoverBC();" onmouseout="unhoverBC();"><img src="img/bconnect_area.png" class="tooltip" rel="Guarda video e ricevi Gemme gratis!" alt="" /></a></div>');

        // ini local storage to save last button state if this html5 feature is available
        var storage = false;
        try {
            if( window && 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 < 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'));
        //]]>

How can I fix it?

share|improve this question
    
Make sure the element you are looking for is viewable when moving_to_element. Also, check this – makeMonday Nov 2 '15 at 15:17
    
Normally, when I click on the element begins the script (document.write ecc) covering the current page and to display a video. I think that everything is concentrated to the last part of the script: // embed supersonic script (function(d,t){ var g = d.createElement(t), s = d.getElementsByTagName(t)[0]; g.async = true; g.src = ('https:' != location.protocol ? 'jsd.supersonicads.com'; : 'supersonicads.cotssl.net') + '/inlineDelivery/delivery.min.gz.js'; s.parentNode.insertBefore(g,s); }(document,'script')); //]]> – – Alberico Mongillo Nov 3 '15 at 12:33
    
It would be necessary to check the DOM in the moment you try to perform the action. Could you post the HTML too? The selenium docs states about the MoveTargetOutOfBoundsException: Indicates that the target provided to the actions move() method is invalid - outside of the size of the window. So looks like that element is not available in the DOM when you perform the action. – makeMonday Nov 3 '15 at 15:52
    
One more thing, you are doing this with Firefox, right? – makeMonday Nov 3 '15 at 15:53
    
I assume move_to_element is outside of the browser boundary. Can you open the firefox with larger screen size, e.g. 1366x768 or even 1920x1080 – mootmoot Apr 5 at 16:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.