我需要獲取當前URL。拆分該URL並將其存儲在一個字符串中。 我曾嘗試是 -C#和selenium:獲取當前URL並存儲在一個字符串中
String urlSecondpart = this.getDriver().getCurrentUrl().Split("https://stackoverflow.com/a/")[1];
這將打開一個新的URL不是當前URL
我需要獲取當前URL。拆分該URL並將其存儲在一個字符串中。 我曾嘗試是 -C#和selenium:獲取當前URL並存儲在一個字符串中
String urlSecondpart = this.getDriver().getCurrentUrl().Split("https://stackoverflow.com/a/")[1];
這將打開一個新的URL不是當前URL
在這裏,我使用的是Firefox配置文件作爲一個例子
FirefoxProfile firefoxProfile = new FirefoxProfile();
// todo: initialize your profile using firefoxProfile.SetPreference
IWebDriver driver = new FirefoxDriver(firefoxProfile);
string url = driver.Url; // get the current full URL
然後使用標準字符串操作來提取你想要的東西。
對於細節SetPreference
和設置配置文件,請參閱http://www.seleniumhq.org/docs/
這不起作用。它不承認getDriver()。 – user3285912
我把getDriver()放在你的代碼中。我修改過並向您顯示了我用來訪問'getDriver()'的步驟。 – ydoow
這不是給我當前的URL。它是打開一個新的瀏覽器。 – user3285912
你正在做的事情錯在你的代碼,但你有沒有貼足以讓我們看看這個問題。做一些閱讀並創建一個2行腳本,並確保基本功能正常。
IWebDriver driver = new FirefoxDriver();
String currentURL = driver.Url;
如果他們不是,你有東西安裝不正確或版本不匹配。修復並再試一次。如果它正在工作,則必須在腳本啓動時放置一個斷點並遍歷代碼,直到發現問題爲止,才能調試腳本。
閱讀How to create a Minimal, Complete, and Verifiable example,特別是關於如何調試小程序的最後一個鏈接。
你能告訴你目前得到的是什麼嗎?你的預期輸出是什麼? –
[我們如何獲取Selenium RC for C#中當前頁面的URL?](http://stackoverflow.com/questions/29569699/how-do-we-get-the-url-of-the -current-page-in-selenium-rc-for-c) –
你能否給我們提供getDriver()實現? –