3

I tried to use ActionChains to duplicate tab with shortcut key ALT+D and ALT+ENTER. And here's the code from user:5168011:

action_chains = ActionChains(driver)
action_chains.key_down(Keys.ALT).send_keys('d').perform()
action_chains.key_down(Keys.ENTER).perform()
action_chains.key_up(Keys.ALT).key_up(Keys.ENTER).perform()

However, it just doesn't work. I've tried the code both using Chrome and Firefox as web-driver, tried in both Linux and Win10, and also tried Keys.ALT and Keys.LEFT_ALT and even used send_keys function to send the Unicode of ALT and LEFT_ALT. But it just looked like it didn't press the ALT key at all.

I suspect that ALT key didn't be pressed because of my another test: if I select an input box as element and use the code:

action_chains.key_down(Keys.ALT, element=element).key_down(Keys.SHIFT, element=element).send_keys('d').perform()

it will show "D" in the text box. However, in reality if I chick the text box and press ALT+SHIFT+d, it will show nothing. So I suggest that key_down(Keys.ALT, element=element) doesn't work and it looks just like action_chains.key_down(Keys.SHIFT, element=element).send_keys('d').perform() and that's why it will show "D" in the text box.

By the way, after test I found that my Keys.SHIFT and Keys.CONTROL works well, so maybe the problem is just for ALT. Is this because of the selenium version? I searched the Internet and didn't find the similar problem...

Jason Lin
  • 63
  • 1
  • 6
  • you want to open the same URL in new tab ? – cruisepandey Jul 23 '18 at 04:54
  • Actually I want to use the ALT key to do something else, and this is just an example. What I really want to do is add the "duplicate tab shortcut key" extension to the chrome, and use ALT+SHIFT+D to duplicate the tab with the history of the duplicated tab kept. – Jason Lin Jul 23 '18 at 06:04
  • Possible duplicate of [How to send keyboard shortcut ALT SHIFT z (hotkey) with Selenium2?](https://stackoverflow.com/questions/11520341/how-to-send-keyboard-shortcut-alt-shift-z-hotkey-with-selenium2) – Ashok kumar Ganesan Jul 23 '18 at 07:58
  • Anyone can run the codes above? I think the problem is the environment and maybe I need information of OS, selenium version, driver version, and Chrome version or Firefox version? – Jason Lin Jul 31 '18 at 17:14

0 Answers0