Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Login and Logout Example in WebDriver:-

package scs;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class EfixmanLogin {

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","c:\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("http://efixman.com//customer/login");
    WebElement txtname = driver.findElement(By.name("customerEmail"));
    txtname.sendKeys("test@gmail.com");
    WebElement txtpass = driver.findElement(By.name("customerPassword"));
    txtpass.sendKeys("12345");
    WebElement btn = driver.findElement(By.className("login100-form-btn"));
    btn.click();
    driver.findElement(By.linkText("Logout")).click();
    driver.switchTo().alert().accept();

}

}


//Key Point:-    By.className() :-   if name,id is not available in HTML elements then we can use class locator in web driver 



driver.switchTo().alert() :-  It is used to manage alert box and press ok button.




Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post