0

On a web page, I am able to perform the right click on a link but not able to select the first option which is 'Open link in a new tab'.

Following are the details:

Selenium WebDriver - v3.14.0
Selenium WebDriver Support - v3.14.0
Chrome Driver - v2.41.0
Visual Studio 2017 in Windows 10 (Selenium C#)
Chrome Browser - 69.0.3497.100 (64 Bit)

Please let me know how to handle this. I have searched this forum but I got results related to Firefox only.

Below is the code I am using:

public void RightClickByXPathAndSelectOption(string webElementXPath)
{    
    Actions action = new Actions(driver);
    action.ContextClick(driver.FindElement(By.XPath(webElementXPath))).SendKeys(Keys.ArrowDown).SendKeys(Keys.Enter).Build().Perform();
}
Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
  • Please provide the HTML, JavaScript, or C# code you are using. – RyanNerd Sep 19 '18 at 07:24
  • @RyanNerd, Code is added – Chackravarthi Jaganathan Sep 19 '18 at 08:08
  • @ChackravarthiJaganathan there are alot of formatting options in the editor. Please get used to using them ! – Felix D. Sep 19 '18 at 08:10
  • 1
    [How do I format my code blocks?](https://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks) – Liam Sep 19 '18 at 08:12
  • *results related to Firefox only.* Selenium is browser agnostic. It doesn't matter if your using chrome or firefox the commands should be the same – Liam Sep 19 '18 at 08:13
  • @Liam, I am not facing a problem in Right Clicking. My problem is that the first option after the right click is not getting selected. – Chackravarthi Jaganathan Sep 19 '18 at 08:24
  • 1
    I see what you mean, this is what you want [How to open a new tab using Selenium WebDriver with Java?](https://stackoverflow.com/questions/17547473/how-to-open-a-new-tab-using-selenium-webdriver-with-java). Ignore the Java bit, the commands are the same in C# – Liam Sep 19 '18 at 08:31
  • 1
    In fact there is a [c# answer](https://stackoverflow.com/a/17558909/542251) – Liam Sep 19 '18 at 08:32
  • @Liam, The problem is, when I Right Click on a link, I get a menu (the first option in that menu is 'Open link in a new tab', this can be selected manually with the Down (1 time) and Enter key but this does not happen via Selenium using the code above. I also dont want to open new tab and paste the link in that tab as the link is complex and many number of links are also involved. – Chackravarthi Jaganathan Sep 19 '18 at 09:04

0 Answers0