Can I control + A and then somehow get the text that was highlighted with the control + A? All in Selenium Python.
Asked
Active
Viewed 3,850 times
1 Answers
3
I think something like this should work
from selenium.webdriver.common.keys import Keys
src_elem = find_element_by_name("source_element")
dist_elem = find_element_by_name("distance_element")
src_elem.send_keys(Keys.CONTROL + 'a') # select all the text
src_elem.send_keys(Keys.CONTROL + 'c') # copy it
dist_elem.send_keys(Keys.CONTROL + 'v') # paste
In case that is not enough try clicking on the element before sending keys to it, like this:
from selenium.webdriver.common.keys import Keys
src_elem = find_element_by_name("source_element")
dist_elem = find_element_by_name("distance_element")
src_elem.click()
src_elem.send_keys(Keys.CONTROL + 'a') # select all the text
src_elem.send_keys(Keys.CONTROL + 'c') # copy it
dist_elem.click()
dist_elem.send_keys(Keys.CONTROL + 'v') # paste

Prophet
- 32,350
- 22
- 54
- 79
-
instead of pasting it to another element, can I save it in a variable and for example print it in the terminal? – quiteLost24 Jun 21 '21 at 18:24
-
1yes, but this is not exactly what you asked about :) – Prophet Jun 21 '21 at 18:27
-
Sorry. Can you help me with the new question? – quiteLost24 Jun 22 '21 at 06:06
-
1Yes, but this is definitely a new question. So please accept this my answer since I answered what you asked about, and I guess I answered correctly, and after that please ask a new question. – Prophet Jun 22 '21 at 07:02