1

I am using Selenium and JavascriptExecutor. I need to make a script/function that ctrl+clicks on an element on a webpage. I know how to make a normal click, WebDriver.ExecuteScript("arguments[0].click();", var), but is it possible to ctrl-click (opening a new tab).

Thanks for your time.

Reporter
  • 3,897
  • 5
  • 33
  • 47
  • HTMLElement.click() does not have any modifiers, (to my knowledge). What javascript could i write, to ctrl-click the element I have as a parameter in ExecuteScript(). – Peter Bandsholm Sep 17 '20 at 09:25
  • Try to use `var.sendKeys(Key.Control)` before clicking it or construct your own click event and dispatch it to the element. – Titus Sep 17 '20 at 09:35
  • @PeterBandsholm Does [this](https://stackoverflow.com/questions/46201035/opening-a-new-tab-using-ctrl-click-combination-in-selenium-webdriver/46214265#46214265) or [this](https://stackoverflow.com/questions/57730636/how-to-open-a-link-embeded-in-a-webelement-with-in-the-main-tab-in-a-new-tab-of/57733103#57733103) discussion help you? – undetected Selenium Sep 17 '20 at 12:14
  • @DebanjanB unfortunately no.. it has to be javascript code, called by JavascriptExecutor. – Peter Bandsholm Sep 17 '20 at 13:10
  • 1
    Why you should only use javascript? There's no a reliable way to simulate a key press in JS for security reasons. –  Sep 17 '20 at 13:47

0 Answers0