Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
gardentools
Posts : 1
Join date : 2012-02-17

Open link in new tab using Chrome driver and C#? Empty Open link in new tab using Chrome driver and C#?

Fri Feb 17, 2012 11:58 pm
Hi everyone,

I'm having a problem getting Selenium to act as though a link was clicked to open it up in a new tab, rather than in a new window which the link defaults to. I'm using the Chrome driver and C# in visual studio.

I know that in chrome normally if you hold down the control key and then click a link as normal with the left mouse button it will open in a new tab. However I seem to be failing to achieve this. So far I have the code:

driver = new ChromeDriver("C:/");
Actions testAction = new Actions(driver);
testAction.KeyDown(OpenQA.Selenium.Keys.LeftControl);
testAction.Click(driver.FindElement(By.Id("linktoclick")));
testAction.KeyUp(OpenQA.Selenium.Keys.LeftControl);
testAction.Build().Perform();

The logic being I build up a sequence where the left control button is pressed down, then the link is clicked, then the left control is released. This doesn't seem to work though - the link still opens in a new window. Does anyone have an idea why, or a better way to go about doing this?

Thanks in advance.
Back to top
Permissions in this forum:
You cannot reply to topics in this forum