Friday, March 3, 2023

xpath


locators

 id

name

cssSelector

Xpath

className

tagName

linkText

partialLinkText


Xpath - Firebug and Firepath - Chropath

-----------

<input type="email" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="username" spellcheck="false" tabindex="0" aria-label="Email or phone" name="identifier" autocapitalize="none" id="identifierId" dir="ltr" data-initial-dir="ltr" data-initial-value="" badinput="false">



//tagName[@attribute='value'] - Relative Xpath, Absolute xpath, partial xpath



//input[@name='identifier'][@id='identifierId']


//input[@name='identifier' and @id='identifierId']



//input[@id='identifierId']



//*[@id="identifierId"]

//*[@id="identifierId"]


//input[@name='q']


//*[@id="view_container"]/div/div/div[2]/div/div[1]/div/form/content/section/div/content/div[1]/div/div[1]/div/div[1]


//html/


<input type="submit" class="button" value="Submit">

<input type="submit" class="button" value="Submit">`


XPATH SYNTAX

-----------------

//tagName[@attribute='value']

//tagName[@attribute='value'][@attribute='value'][@attribute='value']

//tagName[starts-with(@attribute,'value')]

//tagName[contains(@attribute,'value')]

//tagName[text()='value']

//tagName[contains(text(),'partialvalue')]

//tagName[@attribute='value']/..

//tagName[@attribute='value']/parent::tagname

//tagName[@attribute='value']/following-sibling::tagname

//tagName[@attribute='value']/preceding-sibling::tagname[1]


CSS SYNTAX

-------------------

input[id='identifierId']

input[id='identifierId'][type='email']

input[id^='identifie'] - starts-with

input[id$='tifierId'] - ends-with

input[id*='tifier'] - contains

#identifierId - id

tagName - tagName

.Xb9hP - className

input#identifierId.whsOnd.zHQkBf[type='email']

div.aCsJod.oJeWuf > div > div:first-child

div.aCsJod.oJeWuf > div > div:last-child

div.aCsJod.oJeWuf > div > div:nth-child(2)

div[jsname='dWPKW'] > div > div > div > div:nth-child(2)













Wednesday, March 1, 2023

Selenium Basic code

 import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.edge.EdgeDriver;

import org.openqa.selenium.firefox.FirefoxDriver;


public class SelIntroduction {


public static void main(String[] args) {

//Invoking Browser

//Chrome - ChromeDriver exten->Methods close get

//Firefox- FirefoxDriver ->methods close get

// WebDriver  close  get

//WebDriver methods + class methods

// Chrome

System.setProperty("webdriver.chrome.driver", "/Users/rahulshetty/Documents/chromedriver");

WebDriver driver = new ChromeDriver();


//Firefox

System.setProperty("webdriver.gecko.driver", "/Users/rahulshetty/Documents/geckodriver");

WebDriver driver1 = new FirefoxDriver();

//Microsoft Edge

System.setProperty("webdriver.edge.driver", "/Users/rahulshetty/Documents/msedgedriver");

WebDriver driver2 = new EdgeDriver();

driver.get("https://rahulshettyacademy.com");

System.out.println(driver.getTitle());

System.out.println(driver.getCurrentUrl());

driver.close();

//driver.quit();


}


}