Documente Academic
Documente Profesional
Documente Cultură
Log
PageLoad strategy
Profile
Notifications
Certification Error
Proxy
To default download
Firefox
//if path is not set then we need to pass the path of download driver
It creates a new fierfox its own profile, its like a firefox newly installed
options.PageLoadStrategy = PageLoadStrategy.Eager;
options.SetPreference("dom.webnotifications.enabled", false);
options.AcceptInsecureCertificates = true;
option.SetPreference("network.proxy.type", 1);
option.SetPreference("network.proxy.http", "myproxy.com");
option.SetPreference("network.proxy.http_port", 3239);
String downloadFolderPath = @"c:\temp\";
profile.SetPreference("browser.download.folderList", 2);
profile.SetPreference("browser.download.dir", downloadFolderPath);
profile.SetPreference("browser.download.manager.alertOnEXEOpen", false);
profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword, application/binary,
application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip,
application/x-zip-compressed, application/download, application/octet-stream");
Chrome
IWebDriver driver = new ChromeDriver();
options.AddArguments("start-maximized");
DesiredCapabilitiescapabilities = newDesiredCapabilities();
capabilities.SetCapability(ChromeOptions.Capability, options);
DesiredCapabilitiesdc = DesiredCapabilities.Chrome();
dc.SetCapability(ChromeOptions.Capability, options);
IWebDriver driver = new RemoteWebDriver(dc);
options.AddArguments("--log-level=2");
options.AddArguments("--log-net-log=.\\NetLog.log");
options.AddArguments("--disable-infobars");
options.AddArguments("ignore-certificate-errors");
IE
InternetExplorerOptions options = new InternetExplorerOptions() {
IntroduceInstabilityByIgnoringProtectedModeSettings = true,
EnableNativeEvents = true,
IgnoreZoomLevel = true,
EnsureCleanSession = true}
Iwebdriver driver = new InternetExplorerDriver("path of iedriver",options);
Edge
edge should be closed before running again
Navigate To URL
RefreshPage
BackPage
ForwardPage
To get title
To get Current URL
To Page source
Explicit Wait
Locating Eelements
Switch to Frames
Switch to windows
Switch between browser windows or tabs
JavaScript Executor
How To Login Into Any Site If It Is Showing Any Authentication Pop-Up For Username And Password?
Broken links
Driver.Url = "https://www.amazon.in/";
Driver.Navigate().Refresh();
Driver.Navigate().Back();
Driver.Navigate().Forward();
Driver.Manage().Timeouts().SetPageLoadTimeout(newTimeSpan(10));
Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
Driver.Manage().Window.Maximize();
Driver.Close();
Driver.Quit();
driver.FindElement(By.ClassName("className"));
driver.FindElement(By.CssSelector("css"));
driver.FindElement(By.Id("id"));
driver.FindElement(By.LinkText("text"));
driver.FindElement(By.Name("name"));
driver.FindElement(By.PartialLinkText("pText"));
driver.FindElement(By.TagName("input"));
driver.FindElement(By.XPath("//*[@id='editor']"));
driver.FindElement(By.Id("id")).Click();
driver.FindElement(By.Id("id")).SendKeys("someText");
driver.FindElement(By.Id("id")).Clear();
driver.FindElement(By.Id("id")).Submit();
Stringinner Text = driver.FindElement(By.Id("id")).Text;
Bool isEnabled = driver.FindElement(By.Id("id")).Enabled;
Bool isDisplayed = driver.FindElement(By.Id("id")).Displayed;
Bool isSelected = driver.FindElement(By.Id("id")).Selected;
act.DoubleClick(driver.FindElement(By.Name("click"))).Build().Perform();
act.MoveToElement(driver.FindElement(By.Name("click"))).DoubleClick();
act.MoveToElement(driver.FindElement(By.Name("one"))).ClickAndHold() .
MoveToElement(driver.FindElement(By.Name("seven"))).Release().Build().Perform();
act.ClickAndHold(driver.FindElement(By.Name("one"))).
Release(driver.FindElement(By.Name("seven"))).Build().Perform();
act.SendKeys(Keys.Alt + Keys.F4).Build().Perform();
act.DragAndDrop("Elememtsource", "elemnetTarget");
driver.SwitchTo().Frame("iframe_a");
driver.FindElement(By.Id("name")).SendKeys("hi");
driver.SwitchTo().DefaultContent();
Screenshotscreenshot = ((ITakesScreenshot)driver).GetScreenshot();
screenshot.SaveAsFile(@"pathToImage", ImageFormat.Png);
js.executeScript("arguments[0].click();", button);
js.executeScript("alert('Welcome to Guru99');");
REST API
Click on element
To send text
clear the text on element
to sumit
To get text
To check element is enabled
To check element is displayed
To check element is selected
To click on element
To double click
To click on Yes
To click on No
To send keys on popup
To get the text of pop-up
Selnium is collection of client library avilabe in the form of API for diffreint languages
jsonwire protoal is client over http
REST API
Absolute XPath - / - From root html/body/div[1]/section/div/div/div/div[1]/div/div/div/div/div[3]/div[1]/div/h4[1]/b
Exceptions
DriverServiceNotFoundException
ElementNotVisibleException
InvalidCookieDomainException
InvalidElementStateException
InvalidSelectorException
NoAlertPresentException
NoSuchElementException
NoSuchFrameException
NoSuchWindowException
NotFoundException
StaleElementReferenceException
UnableToSetCookieException
UnhandledAlertException
WebDriverException
WebDriverTimeoutException
XPathLookupException
Reverse a string keeping its position string StringToReverse= "Hello this is suresh";
string[] SplitStrings = StringToReverse.Split(' ');
string StringRev = string.Empty;
};
int pair = 0;
Console.WriteLine(pair);
Console.ReadKey();
return pair;
}
Key = s.Attribute("Key").Value,
Reading XML Value = s.Attribute("Value").Value
});
globalSettings.ToList().ForEach(s =>
{
GlobalSetting.Add(s.Key, s.Value);
});
runSettings.ToList().ForEach(s =>
{
RunSetting.Add(s.Key, s.Value);
});
Console.ReadLine();
}
Reading Json Managenuget : Newtonsoft.Json
Refernce System.Web.Extension
using System.Web.Script.Serialization;
using System.IO;
using Newtonsoft.Json;
Sum Console.WriteLine(numbers.Sum());
Count Console.WriteLine(numbers.Count());
Average Console.WriteLine(numbers.Average());
WithoutLinq Linq
int[] numbers = { 11, 2, 3, 4, 1, 5, 6, 7, 8, 9 }; Console.WriteLine(numbers.Where(x => x % 2 == 0).Min());
int? min = null;
foreach (int number in numbers)
{
if (!min.HasValue || min<number)
{
min = number;
}
}
Console.WriteLine(min);
int sum = 0;
foreach (int number in numbers)
{
sum += number;
}
Console.WriteLine(sum);
Console.WriteLine(numbers.Length);
WithoutLinq
int[] numbers = { 11, 2, 3, 4, 1, 5, 6, 12,17, 8, 9 };
int? min = null;
foreach (int number in numbers)
{
if (number%2==0)
{
if (!min.HasValue || min < number)
{
min = number;
}
}
}
Console.WriteLine(min);