I have an alert box that shows a URL in the text input area and copies the link to the clipboard. I want to be able to open a new tab, and paste the URL into the address bar.
I have tried :
var generatedLink = System.Windows.Forms.Clipboard.GetText();
_chromeDriver.Navigate().GoToUrl(generatedLink);
generatedLink returns ""
I have also tried :
Attempt 1:
((IJavaScriptExecutor)_chromeDriver).ExecuteScript("window.open();");
List<String> tabs = new List<String>(_chromeDriver.WindowHandles);
_chromeDriver.SwitchTo().Window(tabs[1]);
_chromeDriver.FindElement(By.XPath("//body")).SendKeys(Keys.Control + "l");
_chromeDriver.FindElement(By.XPath("//body")).SendKeys(Keys.Control + "v");
SendKeys(Keys.Control + "l") does not select the address bar like it should
SendKeys(Keys.Control + "v") does not paste the text
I know that the text is copied because when I debug the test, I can paste the copied text into Notepad without any problems.
The following is where the copying occurs:
const url = window.location.host + urlPattern.stringify(newUrlParameters) + queryString;
(navigator as any).clipboard.writeText(url)
.then(() => window.prompt('Link copied to clipboard!', url))
.catch(() => window.prompt('Copy to clipboard: Ctrl+C, Enter', url));