CSS selectors in Selenium webdriver:
==============================
CSS selectors has more Advantage than Xpath ie CSS is much more faster than the xpath
In IE Xpath works very slow, where as Css works faster when compared to Xpath.
Syntax:
----------
tagName[attributename=attributeValue]
Example 1: input[id=email]
Special characters in CSS:
===========================
In CSS there are two special characters.
1. dot(.) refers to class.
Syntax:css=input.submitbtn
input.rcbutton
2. Hash(#) refers to Id
Example:
CSS=input#email
Example:
========
package testngdemo;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class FileUploadDemo {
WebDriver driver;
@BeforeTest
public void openBrowser() {
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
}
@Test
public void testUpload() throws InterruptedException {
driver.get("https://www.gmail.com");
WebElement element_Username = driver.findElement(By.cssSelector("input[id=Email]"));
element_Username.clear();
element_Username.sendKeys("rameshat914@gmail.com");
WebElement element_Next = driver.findElement(By.cssSelector("#next"));
element_Next.click();
Thread.sleep(3000);
WebElement element_Paswword = driver.findElement(By.cssSelector("input#Passwd"));
element_Username.clear();
element_Username.sendKeys("rameshat914@gmail.com");
WebElement element_Signin = driver.findElement(By.cssSelector("input.rc-button rc-button-submit"));
element_Next.click();
}
@AfterTest
public void closeBrowser() {
driver.quit();
}
}
==============================
CSS selectors has more Advantage than Xpath ie CSS is much more faster than the xpath
In IE Xpath works very slow, where as Css works faster when compared to Xpath.
Syntax:
----------
tagName[attributename=attributeValue]
Example 1: input[id=email]
Special characters in CSS:
===========================
In CSS there are two special characters.
1. dot(.) refers to class.
Syntax:css=input.submitbtn
input.rcbutton
2. Hash(#) refers to Id
Example:
CSS=input#email
Example:
========
package testngdemo;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class FileUploadDemo {
WebDriver driver;
@BeforeTest
public void openBrowser() {
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
}
@Test
public void testUpload() throws InterruptedException {
driver.get("https://www.gmail.com");
WebElement element_Username = driver.findElement(By.cssSelector("input[id=Email]"));
element_Username.clear();
element_Username.sendKeys("rameshat914@gmail.com");
WebElement element_Next = driver.findElement(By.cssSelector("#next"));
element_Next.click();
Thread.sleep(3000);
WebElement element_Paswword = driver.findElement(By.cssSelector("input#Passwd"));
element_Username.clear();
element_Username.sendKeys("rameshat914@gmail.com");
WebElement element_Signin = driver.findElement(By.cssSelector("input.rc-button rc-button-submit"));
element_Next.click();
}
@AfterTest
public void closeBrowser() {
driver.quit();
}
}
No comments:
Post a Comment