Selenium_with_Java_POC
Selenium_with_Java_POC
1. Introduction to Selenium:
Key Features:
- Cross-browser testing.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.13.0</version>
</dependency>
Code Example:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
driver.get("https://www.example.com");
driver.quit();
4. Locating Elements:
Code Example:
element.click();
Locator Strategies:
- By.id
- By.name
- By.className
- By.xpath
- By.cssSelector
5. Handling Dropdowns:
Code Example:
dropdown.selectByVisibleText("Option1");
6. Handling Alerts:
Code Example:
alert.accept();
Implicit Wait:
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
Explicit Wait:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")));
8. Taking Screenshots:
Code Example:
Code Example:
this.driver = driver;
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.id("login")).click();
Code Example:
import org.testng.annotations.Test;
@Test
driver.get("https://www.example.com");
driver.quit();
<test name="Test">
<classes>
</classes>
</test>
</suite>
12. Generating Reports: