我有一個警告框,它在文本輸入?yún)^(qū)域顯示一個 URL,并將鏈接復(fù)制到剪貼板。我希望能夠打開一個新選項卡,并將 URL 粘貼到地址欄中。我努力了 :var generatedLink = System.Windows.Forms.Clipboard.GetText();_chromeDriver.Navigate().GoToUrl(generatedLink);生成的鏈接返回“”我也試過:嘗試 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") 沒有像它應(yīng)該的那樣選擇地址欄SendKeys(Keys.Control + "v") 不粘貼文本我知道文本被復(fù)制了,因為當(dāng)我調(diào)試測試時,我可以將復(fù)制的文本粘貼到記事本中而不會出現(xiàn)任何問題。以下是復(fù)制發(fā)生的地方: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));
2 回答

當(dāng)年話下
TA貢獻(xiàn)1890條經(jīng)驗 獲得超9個贊
如果要將url設(shè)置為地址欄,解決方法如下:
((IJavaScriptExecutor)Driver).ExecuteScript("navigator.clipboard.readText().then(text => window.location.replace(text));");
或使用TextCopy 包:
Driver.Navigate().GoToUrl(new TextCopy.Clipboard().GetText());
- 2 回答
- 0 關(guān)注
- 459 瀏覽
添加回答
舉報
0/150
提交
取消