Selenium Methods
Selenium Methods
1. FindElement : This method searches for an element in the current page based on the locator like (id, name,
classname, linktext, partialLinkText, cssSelector, xpath).
2. FindElements: This method returns a list of all elements that matches with the specified locator.
Syntax: driver.FindElements(By.Id(""));
Ex: driver.FindElements(By.Id("//a"));
WebDriver Methods:
1. Manage: we can set the timeouts for the webdriver using the Manage().TimeOuts() method.
We can navigate forward and backward in the browser history using Manage.Navigation.
Ex: driver.SwitchTo().Alert().Accept();
Ex:
[TestClass]
public class Practise2
{
private ReadOnlyCollection<string> handles;
[TestMethod]
public void test()
{
IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver();
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitWait =TimeSpan.FromSeconds(5);
driver.Url = "https://secure.indeed.com/auth?hl=en_IN&co=IN&continue=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fin.indeed.com%2F%3Fr
%3Dus&tmpl=desktop&service=my&from=gnav-util-homepage&jsContinue=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fin.indeed.com
%2F&empContinue=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Faccount.indeed.com%2Fmyaccess&_ga=2.11004604.942636905.1682611851-
567037357.1682611851";
driver.FindElement(By.XPath("//button[@id='login-google-button']")).Click();
driver.FindElement(By.XPath("//button[@id='login-facebook-button']")).Click();
handles =driver.WindowHandles;
}
3. Quit: This method closes the current window and ends the WebDriver session.
Syntax: driver.Quit();
4. PageSource: PageSource property is used to get the HTML source code of a web page.
6. WindowHandles: WindowHandles is a property in the selenium WebDriver interface that is used to get a set of all the unique
identifiers of the open browser windows or tabs.
7. Close: Close is a method in the Selenium WebDriver interface that is used to close the current browser.
Syntax: driver.Close();
8. Navigate: Navigate is a method in the Selenium WebDriver interface that is used to a URL or perform browser navigation
actions such as navigating forward or backward in the browser.
Syntax: driver.Navigate().Forward();
driver.Navigate().Back();
driver.Navigate().Refresh();
9. Title: Title is a property in the selenium WebDriver interface that is used to get the title of the current browser.
WebElement methods:
1. TagName: TagName is a property in the selenium WebDriver interface that is used to get the HTML tag name of a web page
element.
Syntax: driver.FindElement(By.TagName(""));
2. Text: Text is a property in the Selenium that is used to get the text content of a web page element. We can use this property to
retrieve the text content of an element and perform further operations based on it.
3.Enabled: Enabled is a property in the selenium that is used to check if a webpage element is enabled or not.In c#, we can use this
property to check if an element is enabled and perform further operations based on it.
3. Selected: Selected is property in the selenium that is used to check if a web page element is selected or not.
4. Location: Location is a property in the selenium WebElement interface that is used to get the location of a web page element.
5. Size: Size is a property in the selenium that is used to get the size of a web page element.
6. Displayed: Displayed is a property in the selenium that is used to check if a web page element is currently displayed on the
page.
7. Clear: Clear is a method in selenium that is used to clear the text from the web page element that accepts input(ex: an input
field).
Syntax: input.Clear();
8. SendKeys: SendKeys is a method in selenium that is used to simulate typing Keys into a web page element that accepts input.
Syntax: input.SendKeys();
9. Submit: Submit is a method in selenium that is used to simulate typing keys into a web page element that accepts input.
Syntax: input.SendKeys();
10. Click: Click is a method in selenium that is used to click an element on a web page.
Syntax: button.Click();
11. GetAttribute: GetAttribute is a method in the selenium that is used to retrieve the value of a specified attribute of a web
element.
12. GetProperty: GetProperty is method is selenium that is used to retrieve the valus of a specified CSS property of a web element.
13. GetCssValue: GetCssValue is a method in the selenium that is used to retrieve the value of a specified CSS property of a web
element.