0

I am using ActionChains functions in firefox headless mode, but it is not working. I have this scrolling div code_scroll = driver.find_element_by_class_name('CodeMirror-scroll') I want to double click inside this div and then copy/paste the whole text. The double_click() function is working fine, I have tested it but i think key_down/keyup or send_keys() functions are not working. Bottomline: The text is not being copied.

P.S. The code is working perfectly fine in normal mode.

Driver configuration:

options = webdriver.FirefoxOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Firefox(options=options, capabilities=capa,executable_path=r''+os.path.dirname(os.path.abspath(__file__))+'\geckodriver.exe')

Code:

code_scroll = driver.find_element_by_class_name('CodeMirror-scroll')
actions = ActionChains(driver)
actions.double_click(code_scroll).perform()
actions.key_down(Keys.CONTROL)
actions.send_keys('a').perform()
actions.send_keys('c').perform()
actions.key_up(Keys.CONTROL)
function_body_content = pyperclip.paste()

I have already tried several answers, regarding setting the manual size of the window, but none of them worked.

Already tried solutions:

1) driver.set_window_size(1440, 900)
2) options.add_argument("--window-size=1920, 1480")
3) options.add_argument('window-size=1920x1480')
4) options.add_argument('--width=1920')
   options.add_argument('--height=1480')

1 Answers1

0

It does not work is headless chrome or firefox. Seems like this is a sort of bug. But you can use PhantomJs webdriver, it allows clipboard paste,

Ayush Raj
  • 11
  • 2