5

There is a similar question concerning Watir-WebDriver.

What is the best way to do Ctrl+click on a DOM element?

asked Jan 23, 2012 at 11:43

4 Answers 4

4

A Google search of "webdriver ctrl click" turned up this result:

Ctrl+click requires three actions: a send_keys action to press the CTRL key, then a click action, and then another send_keys action to release the CTRL key.

answered Jan 23, 2012 at 14:22
4
  • Thanks. What I'm confused about is that send_keys is done with respect to an element (i.e. element.send_keys). What element should I choose here? Commented Jan 23, 2012 at 17:17
  • The wording of the original question suggests you already have an element in mind. Are you asking how to identify that element to Webdriver? Commented Jan 24, 2012 at 2:11
  • Well the element to do the click on is determined. But there is no specific element listening to the "Ctrl" event. Commented Jan 24, 2012 at 9:11
  • The answer may depend upon which event propagation model you use, but I believe you can direct the CTRL key press/release to the body element. Commented Jan 24, 2012 at 15:13
0

for clicking on the link which expected to be opened from new tab use this

WebDriver driver = new ChromeDriver(); 
driver.get("https://www.yourSite.com"); 
WebElement element=driver.findElement(By.xpath("path_to_link")); 
Actions actions = new Actions(driver); 
actions.keyDown(Keys.LEFT_CONTROL) 
 .click(element) 
 .keyUp(Keys.LEFT_CONTROL) 
 .build() 
 .perform(); 
ArrayList<String> tab = new ArrayList<>(driver.getWindowHandles()); 
driver.switchTo().window(tab.get(1));
answered Jun 2, 2020 at 12:22
0

I think your best bet is to use Actions which is described here:

https://stackoverflow.com/questions/17756532/how-to-hold-key-down-with-selenium

You will want to execute the key_down action (for the CONTROL key), then the click action, then the key_up action.

The key codes for non-letter keys are listed here: https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.common.action_chains

answered Jun 6, 2020 at 1:25
-1

The element is nothing but the variable to find the properties of the object so we are using WebElement to find it

WebElement obj = findElement(By.Xpath("")).click(); 
obj.sendkeys("xxxxx");

If you guys want to click submit button you can use code obi.submit(). This code navigates to the next page. It acts as the button click().

dzieciou
10.5k9 gold badges49 silver badges102 bronze badges
answered Dec 3, 2012 at 8:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.