Created
September 5, 2022 01:52
-
-
Save bharathmuddada/92bbb5e3cc1dde22dca893a7a395473d to your computer and use it in GitHub Desktop.
c# Selenium program to identify elements using relative locators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SeleniumRelativeLocators { | |
public static void Main(string[] args) | |
{ | |
new DriverManager().SetUpDriver(new ChromeConfig()); | |
var driver = new ChromeDriver(); | |
driver.Navigate().GoToUrl("https://www.saucedemo.com/"); | |
driver.Manage().Window.Maximize(); | |
var emailLocator = | |
RelativeBy.WithLocator(By.TagName("input")).Above(By.Id("password")); | |
driver.FindElement(emailLocator).SendKeys("standard_user"); | |
var passwordLocator = | |
RelativeBy.WithLocator(By.TagName("input")).Below(By.Id("user-name")); | |
driver.FindElement(passwordLocator).SendKeys("secret_sauce"); | |
var loginbutton = | |
RelativeBy.WithLocator(By.Id("login-button")).Below(By.Id("password")); | |
driver.FindElement(loginbutton).Click(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment