How to work With dynamics id.
Why we use startwith...
When you are automating a web application, first step is to identify the ID for a web element. But when the ID of a web element is dynamically generated, then your tests to fail because the automation tool can’t identify the web element being tested.
So what are these Dynamic ID’s and how we can overcome them?
Dynamic IDs are automatically generated ID attributes attached to any web element such as buttons, text-fields and labels. They typically look like some identifier text combined with an auto-incremented number like these samples: ext-gen216, ext-gen217,ext-gen218
Generally these IDs are generated sequentially in an application. They may change from session to session, or even from window to window. Ext JS in Sencha is a common source of dynamic IDs.
One of the big problems with dynamic IDs is maintaining scripts between versions and even between different runs.
Solutions: How we can overcome the difficulties caused by dynamic IDs?
Use startwith function
suppose <input id= "ext-gen216"/input>
After a new session id is <input id= "ext-gen217"/input>
So every time it is generating a new id so we will take xpath as
//input[starts-with(@id, 'ext-gen')]
Now start-with function will pass your test..
Why use contains function in xpath.??
If you want your xpath shouldn't fail then try using contains function.
How it works?
If text is available there then use
Syntax1- //tagname[contains(text(),'YourText')]
<input class="search-bar-submit fk-font-13 fk-font-bold" type="submit" value="Search"/>
Now in this text is not then we can also use contains..
Syntax2-//tagname[contains(@class,"search-bar-submit fk-font-13 fk-font-bold")]
contains will match the text matching patterns are like..example( my name is ritika)
Patterns
pattern1 = my na
pattern2 = name is
pattern3 = s ritika
<input class="search-bar-submit fk-font-13 fk-font-bold" type="submit" value="Search"/>
No need to write whole value "search-bar-submit fk-font-13 fk-font-bold"
xpath1=//input[contains(@class,"search-bar-submit")]
xpath2=//input[contains(@class,"13 fk-font-bold")]
xpath3=//input[contains(@class,"submit fk-font-13 fk")
Syntax3=//input[contains(@value,"Search")]
Why we use startwith...
When you are automating a web application, first step is to identify the ID for a web element. But when the ID of a web element is dynamically generated, then your tests to fail because the automation tool can’t identify the web element being tested.
So what are these Dynamic ID’s and how we can overcome them?
Dynamic IDs are automatically generated ID attributes attached to any web element such as buttons, text-fields and labels. They typically look like some identifier text combined with an auto-incremented number like these samples: ext-gen216, ext-gen217,ext-gen218
Generally these IDs are generated sequentially in an application. They may change from session to session, or even from window to window. Ext JS in Sencha is a common source of dynamic IDs.
One of the big problems with dynamic IDs is maintaining scripts between versions and even between different runs.
Solutions: How we can overcome the difficulties caused by dynamic IDs?
Use startwith function
suppose <input id= "ext-gen216"/input>
After a new session id is <input id= "ext-gen217"/input>
So every time it is generating a new id so we will take xpath as
//input[starts-with(@id, 'ext-gen')]
Now start-with function will pass your test..
Why use contains function in xpath.??
If you want your xpath shouldn't fail then try using contains function.
How it works?
If text is available there then use
Syntax1- //tagname[contains(text(),'YourText')]
Sometime xpath given by xpath fails so we use contains
If text is available there then use
Sometime text is not available so we can also use contains..
<input class="search-bar-submit fk-font-13 fk-font-bold" type="submit" value="Search"/>
Now in this text is not then we can also use contains..
Syntax2-//tagname[contains(@class,"search-bar-submit fk-font-13 fk-font-bold")]
contains will match the text matching patterns are like..example( my name is ritika)
Patterns
pattern1 = my na
pattern2 = name is
pattern3 = s ritika
<input class="search-bar-submit fk-font-13 fk-font-bold" type="submit" value="Search"/>
No need to write whole value "search-bar-submit fk-font-13 fk-font-bold"
xpath1=//input[contains(@class,"search-bar-submit")]
xpath2=//input[contains(@class,"13 fk-font-bold")]
xpath3=//input[contains(@class,"submit fk-font-13 fk")
Syntax3=//input[contains(@value,"Search")]





0 comments:
Post a Comment