I am using Windows form with c# language. I want to pen the new url in the same page in selenium. How can we open the new url in the same page?
Loading
I am using Windows form with c# language. I want to pen the new url in the same page in selenium. How can we open the new url in the same page?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Dec 25, 2023, 4:35 AM EST
Awesome! Nice to hear, your issue has been resolved.
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Dec 24, 2023, 1:55 PM EST
In Selenium with C#, you can open a new URL in the same browser window by using the Navigate().GoToUrl() method. Here's an example of how you can achieve this in a Windows Forms application:
public partial class YourForm : Form { // Create a Selenium WebDriver instance private IWebDriver driver; public YourForm() { InitializeComponent(); // Initialize the WebDriver (assuming you are using Chrome) driver = new ChromeDriver(); } private void OpenUrlButton_Click(object sender, EventArgs e) { // Get the URL from your textbox or any other source string url = YourTextBox.Text; // Navigate to the new URL in the same browser window driver.Navigate().GoToUrl(url); } // Remember to close the WebDriver when the form is closed private void YourForm_FormClosed(object sender, FormClosedEventArgs e) { driver.Quit(); } }In the above code snippet, I'm assuming that you have a TextBox named YourTextBox where you can input the URL and a button named OpenUrlButton that triggers the navigation.
Mehmet FatihRank #1,475 · 1.1K reputationPosted Dec 25, 2023, 12:54 AM EST
Thanks for your intrest Muhammad Imran. But it is not the thing I want. I have solved the prbolem with the c-following code.
drv.SwitchTo().Window(drv.WindowHandles.ToList().Last());