till part
Important selenium Notes :
Why the return type of the object ChromeDriver is WebDriver
Reason being : WebDriver is an interface , and all its methods are used to automate
the UI are strongly implemented by ChromeDriver object.
Reason of using the chromewebdriver.exe : due to security reasons , an internal api
cannot call the external webbrowser, it needs some kind of exe to invoke and
communicate with the browser.
methods : obj.get(); (opening the brower with the url ).
obj.getTitle(); ( getting the title of the web page).
obj.getPageSource(); (getting the page source).
obj.quit(); (quit the all instances of the browser opened by selenium).
obj.close(); (Close the current instanc of the brower opened by selenium).
obj.navigate().back();
obj.navigate().forward();
Types of locators :
1) Name.
2) Css.
3) xpath.
4) ID.
5) ClassName.
methods findElement(By.ID())
not every elemet are having the ID , ClassName or name - Xpath and CSS prefered.
1) Every object may not have ID , className or Xpath is prefered.
2) alpha numeric id may vary.
3) confirm the link with anchor "a" tag.
4) Classes should not have spaces - compung elements.
5) Incase two elemets / objects having same property then from top left to right
top to bottom thing applies.
xPath and Css
Double quotes inside the double quotes is not
Xpath :
When xpath starts with html do not start from html
no direct way to get css in chrome
Custom Xpath
$x()(in console)(xpath)
$()(css)
Xpath Syntax:
//tagName[@attribute='value']
//button[@name='login']
//input[@placeholder='Email address or phone number']
.sendKeys() do not clear the existing text in the edit box
driver.findElement(By.cssSelector())
tagName[attribute='value'] - css
tagName[attribute='value'] - css
tagName#id
tagName.classname (avoid compound className)
<input name="username123">
//input[contains(@attribute,'value')]
input[Attribute='value']
Identify the parent uniqely
//div[@class='lst-c']/div/div[2]/div/input
//div[@class='lst-c']/div/div[2]/div/input
//div[@class='rt-tr -odd']/div/div[2]/div/span/a
traverse the child
//div[@class='rt-tr-group']/div/div[2]/div/span[@id='see-book-Learning JavaScript
Design Patterns']
//"[text()=' ']
"//h4/a[]
//*[@ui='tablist1-tab1']/parent::ul - going back to the parent
//*[@id='tablist-tab1']/following-sibling::li[2]
www.qaclickacademy.com/interview.php
//li[@id='tablist-tab1']/following-sibling::li[3]
//li[@id='tablist-tab1']/parent::ul
//li[@role='tab']/following-sibling::li[4]
//li[@role='tab']/
//li[@aria-labelledby='ui-id-3']/parent::ul
//label[contains(text(),'Email or mobile phone number')]
//a[contains(text(),'Headlines')]
//a[Contains(text(),'Chennai')
//h2[@class='oOr8M uP1HId Ir3o3e cS3HJf']
//Compunding class rule is not applicable in case of xpath etc . only that rule is
applicable to By.findElementByClassName();
for selecting a dropdown : use Select ( class )
and pass on the object of WebElement class ( object referencing to the location of
the webelements)
objChrome.findElemets().size(); -> Returns the number of the child elements
(similar kind of object note wtrite the generic css / class ) .
Inscase wants to traverse the code .
List<WebElemet> objElements = objChrome.findElemets();
Asert.assertTrue() checks if the statement is true
Asert.assertFalse() checks if the statements is faulse
objChrome.getText() get the text fromn the screen .
objChrome.getAttribute() get the attribute of a tag.
objChrome.findElemet(By.Id()).isEnabled() check if the checkbox is enabled or not .
objChrome.isEnabled();
findEelemets() ;
Return type is WebElemet
.size() is similar to the .count function in the vb
.get(index) (using the index to get the elements) similar to obj(index).count in
the vbscript
.trim() similar to the trim(string) in the vbscript .
Arrays.asList(items) : converting the array into arraylist
with the list object one can use the contains function.
types of wait :
Implecit wait
Explicit wait
Thread.sleep
Fluent wait
objChrome.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
Change the view from debugging to pakage explorer view / soulution explorer view ;
there is a table symbol on the left most to corner and click on that .
there will be java click on that the pakage explorer will get opened.
// Waiting 30 seconds for an element to be present on the page, checking
// for its presence once every 5 seconds.
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("foo"));
}
});
Wait is a class here , Fluent
get windows handle uses to swicth between the tabs of the browser.
Set<String> windows = driver.getWindowHandles();
Iterator<String> it = windows.iterator();
String parentID = it.next();
String childID = it.next();
driver.switchTo().window(childID);
Using Actions (class in selenium one can automate the sendkeys and the right
click )
For switching to nested frame :
driver.switchTo().frame("parent frame name ")
driver.switchTo().frame("child frame")
how to move down to a specific section
WebDriver objCheck = new ChromeDriver();
WebElement objLocator = objCheck.findElemet(By.cssLocator());
WebElement objLocator1 = objLocator.findElemet(By.cssLocator());
passing the send keys (means in form of string variables )
String clickonlinkTab=Keys.chord(Keys.CONTROL,Keys.ENTER);