- gardentools
- Posts : 1
Join date : 2012-02-17
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.
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.
Permissions in this forum:
You cannot reply to topics in this forum