Selenium webdriver is opening the browser, but not opening the given url
For anyone encountering this issue, please make sure that you have installed the chromedriver (or whatever driver is available for your browser). For chrome you first need to check your information and find out the version from chrome://version/
then from, https://sites.google.com/a/chromium.org/chromedriver/downloads
download the corresponding driver and copy the filepath into the the executable_path section.
Having some trouble when opening chrome browser with Selenium ChromeDriver
For question 2,3 you can use below code
(use DriverService.Dispose(); to manually dispose driver service) :
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace MyProject
{
public class Browser : IDisposable
{
bool disposed = false;
IWebDriver Driver;
public Browser()
{
//Chrome Driver copied on startup path
ChromeDriverService driverService = ChromeDriverService.CreateDefaultService(Application.StartupPath, "chromedriver.exe");
//hide driver service command prompt window
driverService.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
//hide browser if you need
//options.AddArgument("headless");
//or this to hiding browser
//options.AddArgument("--window-position=-32000,-32000");
//On offer Dona bhatt for disable automated test notification
options.AddExcludedArgument("enable-automation");
//options.AddArgument("disable-infobars");
Driver = new ChromeDriver(driverService, options);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposed)
return;
if (disposing)
{
Driver.Close();
Driver.Quit();
Driver.Dispose();
DriverService.Dispose();
}
disposed = true;
}
//this method for navigation
public string Navigate(string url)
{
string page = string.Empty;
try
{
Driver.Navigate().GoToUrl(url);
page =Driver.PageSource;
}
catch
{
}
return page;
}
//this method for wait to an element be visible by element ID
private void WaitUntilLoad(string id, int timeOut)
{
WebDriverWait waitForElement = new WebDriverWait(Driver, TimeSpan.FromSeconds(timeOut));
try
{
waitForElement.Until(ExpectedConditions.ElementIsVisible(By.Id(id)));
}
catch (WebDriverTimeoutException e)
{
}
}
}
}
Use this class:
using(Browser brw=new Browser())
{
string pageSource=brw.Navigate("My URL");
}
Related Topics
How to Send Image With Post Request
I Want to Detect the End of Scroll Event
Re-Prompt User After Invalid Input in Java
Is There a Simpler Way to Check Multiple Values Against One Value in an If-Statement
Hibernate Error Executing Ddl Via Jdbc Statement
Why Am I Getting the Error "The Method Is Undefined for the Type"
How to Convert Minutes to Hours and Minutes (Hh:Mm) in Java
Error Says It's Dividing by Zero While It's Not Initialised as Zero
Checking If a String Contains Only Digits (Isdigitmethod Required)
How to Get Summation of Pair(Key) Values in a Map in Java
Serialize a Double to 2 Decimal Places Using Jackson
How to Print Even and Odd Position Characters of an Array of Strings in Java
How to View Apache Parquet File in Windows
How to Call a Database Function Using Spring Data Jpa
Better Way to Detect If a String Contains Multiple Words
Pdf to Byte Array and Vice Versa
Eclipse: the Resource Is Not on the Build Path of a Java Project
The Package Org.W3C.Dom Is Accessible from More Than One Module: <Unnamed>, Java.Xml