2

Can I control + A and then somehow get the text that was highlighted with the control + A? All in Selenium Python.

Prophet
  • 32,350
  • 22
  • 54
  • 79
quiteLost24
  • 35
  • 1
  • 6

1 Answers1

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