Web Elements and Element Locators in Selenium
Web Elements and Element Locators in Selenium
i) Web Elements
rn - repository name
ot - Object type
un - ui name
---------------
> Navigate from one URL to another
> Navigate back to previous URL
> Navigate forward
> Refresh the Browser
> Maximize the Browser
Etc...
-----------------------------------
2) Operations on Web Page
> Get Page Title
> Get Page URL
-----------------------------------
3) Operations on Edit box
> Click
> Check Enabled status
> Display status
Etc...
-----------------------------------
6) Operations Image
> Return / Capture Text Area or Error message from a web page
-----------------------------------
8) Operations on Check box
> Locator is an address that identifies a web element uniquely within the webpage.
Locators are the HTML properties of a web element.
id,
name,
className,
tagName,
linkText,
partialLinkText,
cssSelector,
xpath
Download and install Firebug and Firepath plug ins/Add ons for Firefox Browser.
If it Internet Explorer or Chrome, we no need to install any Add on, they provide
built -in Developer Tools (F12) to inspect elements.
Syntax:
Examples:
driver- is Object
id - Element locater
Or
Synatx:
Examples:
driver.findElement(http://By.name("Email")).sendKeys("gcrindia");
Or
WebElement e = driver.findElement(http://By.name("Email"));
e.sendKeys("gcrindia");
------------------------------------------
WebElement e = driver.findElement(http://By.name("signIn"));
e.click();
------------------------------------------
3) className
Example:
driver.findElement(By.className("textboxcolor")).sendKeys("Hyderabad");
----------------------------------------------
4) tagName
Syntax:
By.tagName("tag name value")
Example:
driver.findElement(By.tagName("input")).sendKeys("Hyderabad");
--------------------------------------------------------------
5) linkText
Syntax:
By.linkText("Link Text Value")
Example:
driver.findElement(By.linkText("Gmail")).click();
-----------------------------------------------------
6) paritialLinkText
Syntax:
By.partialLinkText("Partial Link Text Value")
Example:
driver.findElement(By.partialLinkText("Gma")).click();
-----------------------------------------------
7) cssSelector
Syntax:
By.cssSelector("value")
Example:
driver.findElement(By.cssSelector(".gb_m")).click();
---------------------------------------------------
8) xpath
Xpath in XML document shows the direction of software web application's element
location.
Syntax:
By.xpath("xpath value")
driver.findElement(By.xpath(".//*[@id='Email']")).sendKeys("abcdef")