title |
description |
created |
updated |
Selenium (Webdriver) |
Selenium is a automated testing framework used to validate web applications across different browsers and platforms. |
2022-10-23 |
2022-10-23 |
You can use multiple programming languages like Java, C#, Python, etc to create Selenium Test Scripts. Testing done using the Selenium testing tool is usually referred to as Selenium Testing.
- Firefox
WebDriver driver = new FirefoxDriver();
- Chrome
WebDriver driver = new ChromeDriver();
- Internet Explorer
WebDriver driver = new InternetExplorerDriver();
- Safari
WebDriver driver = new SafariDriver();
- Firefox
System.setProperty(“webdriver.gecko.driver”, “/path/to/geckodriver”);
- Chrome
System.setProperty(“webdriver.chrome.driver”, “/path/to/chromedriver”);
- Edge
System.setProperty(“webdriver.edge.driver”, “P/path/to/MicrosoftWebDriver”);
Matcher_function |
Description |
driver.findElement(By.id("q")).sendKeys("Selenium 3"); |
Locating by ID |
driver.findElement(By.name("q")).sendKeys("Selenium 3"); |
Locating by Name |
driver.findElement(By.xpath("//input[@id='q']")).sendKeys("Selenium 3"); |
Locating by Xpath |
driver.FindElement(By.LinkText("edit this page")).Click(); |
Locating Hyperlinks by Link Text |
dom =document.getElementById('signinForm'); |
Locating by DOM |
driver.FindElement(By.CssSelector("#rightbar > .menu > li:nth-of-type(2) > h4")); |
Locating by CSS |
driver.findElement(By.className("profile-header")); |
Locating by ClassName |
driver.findElement(By.tagName("select")).Click(); |
Locating by TagName |
driver.findElement(By.linkText("NextPage")).click(); |
Locating by LinkText |
driver.findElement(By.partialLinkText("NextP")).click(); |
Locating by PartialLinkText |
Matcher_function |
Description |
driver.switchTO().alert.getText() |
to retrieve the alert message |
driver.switchTO().alert.accept() |
to accept the alert box |
driver.switchTO().alert.dismiss() |
to cancel the alert box |
driver.switchTO().alert.sendKeys(“Text”) |
to send data to the alert box |
Matcher_function |
Description |
getTitle() |
used to retrieve the current title of the webpage |
getCurrentUrl() |
used to retrieve the current URL of the webpage |
getPageSource() |
used to retrieve the current page source of the webpage |
getText() |
used to retrieve the text of the specified web element |
getAttribute() |
used to retrieve the value specified in the attribute |
Matcher_function |
Description |
driver.navigate().refresh() |
Refresh Page |
driver.navigate().forward() |
Navigate forwards in the browser history |
driver.navigate().back() |
Navigate backward in the browser history |
Matcher_function |
Description |
isEnabled() |
determines if an element is enabled or not, returns a boolean. |
isSelected() |
determines if an element is selected or not, returns a boolean. |
isDisplayed() |
determines if an element is displayed or not, returns a boolean. |