How to right click in selenium and click save image as in python












0














I am trying to right click with mouse and click save as Image in selenium python.
I was able to perform right click with follwing method, however the next action to perform right click does not work any more. How can I solve this problem?



from selenium.webdriver import ActionChains 
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
driver.get(url)

# get the image source
img = driver.find_element_by_xpath('//img')
actionChains = ActionChains(driver)
actionChains.context_click(img).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.RETURN).perform()









share|improve this question






















  • Is it a requirement that you must right click / save as, or are you just trying to get the image content by whatever means necessary?
    – cody
    Nov 23 at 3:03










  • @cody I need right click /save as or using same session and cookies that selenium browser use when it downloads images not just simple urlretrieve function.
    – 강희명
    Nov 23 at 3:30
















0














I am trying to right click with mouse and click save as Image in selenium python.
I was able to perform right click with follwing method, however the next action to perform right click does not work any more. How can I solve this problem?



from selenium.webdriver import ActionChains 
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
driver.get(url)

# get the image source
img = driver.find_element_by_xpath('//img')
actionChains = ActionChains(driver)
actionChains.context_click(img).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.RETURN).perform()









share|improve this question






















  • Is it a requirement that you must right click / save as, or are you just trying to get the image content by whatever means necessary?
    – cody
    Nov 23 at 3:03










  • @cody I need right click /save as or using same session and cookies that selenium browser use when it downloads images not just simple urlretrieve function.
    – 강희명
    Nov 23 at 3:30














0












0








0







I am trying to right click with mouse and click save as Image in selenium python.
I was able to perform right click with follwing method, however the next action to perform right click does not work any more. How can I solve this problem?



from selenium.webdriver import ActionChains 
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
driver.get(url)

# get the image source
img = driver.find_element_by_xpath('//img')
actionChains = ActionChains(driver)
actionChains.context_click(img).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.RETURN).perform()









share|improve this question













I am trying to right click with mouse and click save as Image in selenium python.
I was able to perform right click with follwing method, however the next action to perform right click does not work any more. How can I solve this problem?



from selenium.webdriver import ActionChains 
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
driver.get(url)

# get the image source
img = driver.find_element_by_xpath('//img')
actionChains = ActionChains(driver)
actionChains.context_click(img).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.RETURN).perform()






python selenium web-crawler






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 at 2:47









강희명

1415




1415












  • Is it a requirement that you must right click / save as, or are you just trying to get the image content by whatever means necessary?
    – cody
    Nov 23 at 3:03










  • @cody I need right click /save as or using same session and cookies that selenium browser use when it downloads images not just simple urlretrieve function.
    – 강희명
    Nov 23 at 3:30


















  • Is it a requirement that you must right click / save as, or are you just trying to get the image content by whatever means necessary?
    – cody
    Nov 23 at 3:03










  • @cody I need right click /save as or using same session and cookies that selenium browser use when it downloads images not just simple urlretrieve function.
    – 강희명
    Nov 23 at 3:30
















Is it a requirement that you must right click / save as, or are you just trying to get the image content by whatever means necessary?
– cody
Nov 23 at 3:03




Is it a requirement that you must right click / save as, or are you just trying to get the image content by whatever means necessary?
– cody
Nov 23 at 3:03












@cody I need right click /save as or using same session and cookies that selenium browser use when it downloads images not just simple urlretrieve function.
– 강희명
Nov 23 at 3:30




@cody I need right click /save as or using same session and cookies that selenium browser use when it downloads images not just simple urlretrieve function.
– 강희명
Nov 23 at 3:30












2 Answers
2






active

oldest

votes


















0














You have to first move to the element where you want to perform the context click
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
driver.get(url)

# get the image source
img = driver.find_element_by_xpath('//img')
actionChains = ActionChains(driver)
actionChains.move_to_element(img).context_click().send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.RETURN).perform()





share|improve this answer































    0














    You can do the same functionality using pyautogui. Assuming you are using Windows.
    -->pyautogui.position()
    (187, 567) #prints the current cursor position



    -->pyautogui.moveTo(100, 200)#move to location where right click is req.



    -->pyautogui.click(button='right')



    -->pyautogui.hotkey('ctrl', 'c') - Ctrl+C in keyboard(Copy shortcut)



    Refer to below link for further
    https://pyautogui.readthedocs.io/en/latest/keyboard.html






    share|improve this answer





















    • This one is good answer However I need to apply it on the headless driver. Sorry for not state detail about question.
      – 강희명
      Nov 23 at 5:32











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440086%2fhow-to-right-click-in-selenium-and-click-save-image-as-in-python%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You have to first move to the element where you want to perform the context click
    from selenium.webdriver import ActionChains
    from selenium.webdriver.common.keys import Keys
    from selenium import webdriver
    driver.get(url)

    # get the image source
    img = driver.find_element_by_xpath('//img')
    actionChains = ActionChains(driver)
    actionChains.move_to_element(img).context_click().send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.RETURN).perform()





    share|improve this answer




























      0














      You have to first move to the element where you want to perform the context click
      from selenium.webdriver import ActionChains
      from selenium.webdriver.common.keys import Keys
      from selenium import webdriver
      driver.get(url)

      # get the image source
      img = driver.find_element_by_xpath('//img')
      actionChains = ActionChains(driver)
      actionChains.move_to_element(img).context_click().send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.RETURN).perform()





      share|improve this answer


























        0












        0








        0






        You have to first move to the element where you want to perform the context click
        from selenium.webdriver import ActionChains
        from selenium.webdriver.common.keys import Keys
        from selenium import webdriver
        driver.get(url)

        # get the image source
        img = driver.find_element_by_xpath('//img')
        actionChains = ActionChains(driver)
        actionChains.move_to_element(img).context_click().send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.RETURN).perform()





        share|improve this answer














        You have to first move to the element where you want to perform the context click
        from selenium.webdriver import ActionChains
        from selenium.webdriver.common.keys import Keys
        from selenium import webdriver
        driver.get(url)

        # get the image source
        img = driver.find_element_by_xpath('//img')
        actionChains = ActionChains(driver)
        actionChains.move_to_element(img).context_click().send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.RETURN).perform()






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 23 at 7:00

























        answered Nov 23 at 6:47









        Kaushik

        518




        518

























            0














            You can do the same functionality using pyautogui. Assuming you are using Windows.
            -->pyautogui.position()
            (187, 567) #prints the current cursor position



            -->pyautogui.moveTo(100, 200)#move to location where right click is req.



            -->pyautogui.click(button='right')



            -->pyautogui.hotkey('ctrl', 'c') - Ctrl+C in keyboard(Copy shortcut)



            Refer to below link for further
            https://pyautogui.readthedocs.io/en/latest/keyboard.html






            share|improve this answer





















            • This one is good answer However I need to apply it on the headless driver. Sorry for not state detail about question.
              – 강희명
              Nov 23 at 5:32
















            0














            You can do the same functionality using pyautogui. Assuming you are using Windows.
            -->pyautogui.position()
            (187, 567) #prints the current cursor position



            -->pyautogui.moveTo(100, 200)#move to location where right click is req.



            -->pyautogui.click(button='right')



            -->pyautogui.hotkey('ctrl', 'c') - Ctrl+C in keyboard(Copy shortcut)



            Refer to below link for further
            https://pyautogui.readthedocs.io/en/latest/keyboard.html






            share|improve this answer





















            • This one is good answer However I need to apply it on the headless driver. Sorry for not state detail about question.
              – 강희명
              Nov 23 at 5:32














            0












            0








            0






            You can do the same functionality using pyautogui. Assuming you are using Windows.
            -->pyautogui.position()
            (187, 567) #prints the current cursor position



            -->pyautogui.moveTo(100, 200)#move to location where right click is req.



            -->pyautogui.click(button='right')



            -->pyautogui.hotkey('ctrl', 'c') - Ctrl+C in keyboard(Copy shortcut)



            Refer to below link for further
            https://pyautogui.readthedocs.io/en/latest/keyboard.html






            share|improve this answer












            You can do the same functionality using pyautogui. Assuming you are using Windows.
            -->pyautogui.position()
            (187, 567) #prints the current cursor position



            -->pyautogui.moveTo(100, 200)#move to location where right click is req.



            -->pyautogui.click(button='right')



            -->pyautogui.hotkey('ctrl', 'c') - Ctrl+C in keyboard(Copy shortcut)



            Refer to below link for further
            https://pyautogui.readthedocs.io/en/latest/keyboard.html







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 23 at 5:15









            Manoj Namburi

            1




            1












            • This one is good answer However I need to apply it on the headless driver. Sorry for not state detail about question.
              – 강희명
              Nov 23 at 5:32


















            • This one is good answer However I need to apply it on the headless driver. Sorry for not state detail about question.
              – 강희명
              Nov 23 at 5:32
















            This one is good answer However I need to apply it on the headless driver. Sorry for not state detail about question.
            – 강희명
            Nov 23 at 5:32




            This one is good answer However I need to apply it on the headless driver. Sorry for not state detail about question.
            – 강희명
            Nov 23 at 5:32


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440086%2fhow-to-right-click-in-selenium-and-click-save-image-as-in-python%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)