Selenium Basics Notes
Selenium Basics Notes
Selenium Basics Notes
com/opentaps
ID id id Always(most preferred)
Style sheet css cssselector this is the last option you have!
13. when you find the source code of particular element , inthat
we find the attribute as id, we can you use it as an locator
when you have id , class and name attributes in the soiurce code of the element
that you want to interact .
then you can use them as locators as bove in 13 step
15. when you find a <a> -> link -> you should use linktext a a locator
16. partial link text as a locator
17. when not to use
id = "username-123", will not use id when it has number in it
class = "leaftaps login username " space is not allowed
name = duplicate not allowed
linktext and partial linktext - <a> whn its not a tag we should not use it
18. to find the webelement , return type short cut is crt2 L
19. link text is an case sensitive so just copy from the source code
20. To handle drop down developed in <select> has select class
dropdown will be created in select tag and under select tag will have option
tag , which will be useful in creting the options in the select tag
21. IN sleenium , to handle the drop down develpoed in the <select> tag has selelct
class ,
this class i sspecially made for drop down
with condition as should have developed in select class(select is an class)
in option tag, you may have an attribut called value in the option tag , using
"..." we can use
dd.selectByValue("....");
XPATH
Absoulte xpath - it should start from / html tag - will give you path from HTML
tag to the element i am searching for(exact x path )
relative xpath - it should start from // - based on the element i am
searching for(it will derive to the particular element)
1. Basics
1.1 attribute based xpath : other attributes as a locators
for example : <label for="username">Username</label>
<input class="inputLogin" type="text" id="username" name="USERNAME"
size="50">
attribute for can be used
when you have css attributes should not be used like size, font all these are
size based locators
Partial
syntax: //tagname[contains@attribute, 'value']
xpath: // form[[contains@action,'']
driver.findElemet(By.xpath("label[@for= 'username']"));
{to check if the xpath is correct just paste it in the find box and check }
Partial :
Syntax : //tagname[containstext() ,'value']
Xpath ; //Label[contains(text(),'erna']
WEB TABLE:
Session 3
Selenium - ADV
snapshot
in target LOcators
ALert
frame
window
SNAPSHOT
//Take ScreenSHot
File Source = driver.getScreenshotAs(OutoutType.FILE);
//Creating an empty image to store my ss
File dest = new File(./snaps/pic001.jpg);
//Merge the ss with image
FileUtils.copyfile(source,dest);
ALert
Example :
Fire alert
Rain ALert
Alarm
Amma wakeup
salary credited
battery low
Basic of alert
Alert is model pop up
Alert is a part js
Members of alerts
Alert text
Text field
button - yes /no
Types of alerts
simplet Alert - only text and one button
confirm alert -
<Frame>
House-> Bedroom-> Bathroom
Bathroom-> bedroom-> house
SESSION $
https://jqueryui.com/draggable/
https://jqueryui.com/droppable/
https://jqueryui.com/selectable/
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.5</version>
</dependency>
Relative xpath
1. Basics
1.1 attribute based xpath: other attributes as a locator - class with space
Equals:
Syntax: //tagname[@attribute = 'value']
xpath: //label[@for = 'username']
Partial:
Syntax: //tagname[contains(@attribute , 'value')]
xpath: //form[contains(@action , '/opentaps')]
Partial:
Syntax: //tagname[contains(text() , 'value')]
xpath: //label[contains(text() , 'erna')]