How to right click in selenium and click save image as in python
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
add a comment |
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
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 '18 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 '18 at 3:30
add a comment |
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
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
python selenium web-crawler
asked Nov 23 '18 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 '18 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 '18 at 3:30
add a comment |
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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 3:30
add a comment |
2 Answers
2
active
oldest
votes
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()
add a comment |
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
This one is good answer However I need to apply it on the headless driver. Sorry for not state detail about question.
– 강희명
Nov 23 '18 at 5:32
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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()
add a comment |
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()
add a comment |
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()
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()
edited Nov 23 '18 at 7:00
answered Nov 23 '18 at 6:47
Kaushik
518
518
add a comment |
add a comment |
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
This one is good answer However I need to apply it on the headless driver. Sorry for not state detail about question.
– 강희명
Nov 23 '18 at 5:32
add a comment |
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
This one is good answer However I need to apply it on the headless driver. Sorry for not state detail about question.
– 강희명
Nov 23 '18 at 5:32
add a comment |
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
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
answered Nov 23 '18 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 '18 at 5:32
add a comment |
This one is good answer However I need to apply it on the headless driver. Sorry for not state detail about question.
– 강희명
Nov 23 '18 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 '18 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 '18 at 5:32
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 '18 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 '18 at 3:30