Professional Documents
Culture Documents
Selenium - Xpath
Selenium - Xpath
Topics to be Covered …
Introduction to Xpath
Benefits of Xpath
Types of Xpath
Xpath Functions
Xpath Axes
Introduction to Xpath
conditions
bookstore
theAbsolute
It isRelative
direct
Xpath toXpath
way starts
findfrom
the element,
the middle
butofthe
thedisadvantage
HTML DOM of
thestructure.
absolute ItXpath
startsiswith
that the
if there
double
areforward
any changes
slash(//),
made
which
in the
meanspathit can
of search
the element
the element
then that
anywhere
Xpath gets
at the
failed.
webpage.
Ex: /html/body/div[1]/section/div[1]/div
RelativeEx:Xpath
//input[@id=‘ap_email’]
Xpath Syntax
Selecting Nodes:
The node is selected by following paths or steps. The most useful path expressions are listed
below:
Expression Description
Predicates are used to find a specific node or a node that contains a specific value.
Expression Description
/bookstore/book[2] Selects the second ‘book’ element that contains the child of the
‘bookstore’ element.
/bookstore/book[last()] elects the last ‘book’ element that contains the child of the
‘bookstore’ element.
//bookstore/book[position()<3] Selects the first two ‘book’ elements that are children of the
‘bookstore’ element.
//title[@lang=‘en’] Selects all the title tags that have lang attribute value as ‘en’
//bookstore/book[price>35.00] Selects all the ‘book’ elements of ‘bookstore’ element which have
‘price’ element value greater than 35
Xpath Functions
Starts-with():
Contains(): is used to find elements whose attribute value
Starts-with()
text():
Contains()
changes Contains()
onisrefresh
used when
or any
theother
value
operation
of any attribute
on webpage,
changes
text() is used to locate element with exact text match.
dynamically.
however starting string remain constant
Syntax:
Syntax: Start-with()
Xpath= //button[text()=’Submit’]
Xpath= //label[starts-with(@id,’message’)]
//button[contains(text(),’Submit’)]
Result:
Result: text()button element with exact text as
This will select
This will select label
buttonelement
elementwhose
whichidcontains
attributetext
start
‘Submit’
‘Submit’
with message.
which Attribute
changes value
dynamically.
can be any thing after
‘message’.
Issue 1: Classes can be confusing and has
boilerplate code
Issue 1: Classes can be confusing and has
boilerplate code
Q: Let’s say I need to
create a Class
component for a
Counter. What all do I
need to do?
Extend “Component” class from React
What is the
solution?
Setting up to embrace state
● Takes the initial state value as the argument const [count, setCount] = useState(0);
super(props);
this.state = {
count: 0
};
}
Using state value
Class Components Function Components
<input <input
type="number" type="number"
name="name" name="name"
value={this.state.count} value={count}
/> />
Updating state
Class Components Function Components
function WithFunctions(props) {
let count = 0; ● Updates count correctly
const handleCountChange = (e) => { ● But, component doesn’t re-render as
count = e.target.value;
count isn’t React state
console.log(count);
};
return (
<div>
<input
type="number"
name="name"
value={count}
onChange={handleCountChange}
/>
</div>
);
}
We can use hooks more
than once in a
component
Curious Cats
useState() keep the state values Other local values are resetted
hooked i.e, doesn’t reset
Don’t overuse state -
only use it if you want
the UI to re-render on
change
Class or Function
components - stick to
using 1 of this
consistently in a project
(We’ll use Functions going forward)
Summary
● Class components
● Hooks are special functions that lets you hook into React
features (eg: state)
● useState() hook enables function components to have
their state
● componentDidMount()
2. What are the different places we can make an ● componentDidUpdate()
● Event handlers
API call in React?
Stateless components
3. How does stateful and stateless components ● Do not deal with state and hence cannot
keep track of changing data
differ? ● Prints out what is given to them via props
or always render the same thing
Until next session 🍃
Thank you for joining in today, we’d love to hear your thoughts and feedback here -
https://forms.gle/tZf3ZLjT1AcqCxV87
Thank you