Monday, 3 June 2024

XPath examples to write in selenium

https://selectorshub.com/xpath-practice-page/

https://www.scientecheasy.com/2019/08/xpath-axes.html/


Syntax  :

//tag[@attribute='value']


1. contains() with hyperlink 

<a href="https://jasper-bi-suite.blogspot.com/2024/06/xpath-examples-to-write-in-selenium.html">XPath examples to write in selenium </a>

//div//h3//a[contains(text(),'XPath examples')]


2. id attribute

<input id="shub34" class="selectors-input jsSelector" title="Email" spellcheck="false" autocomplete="anyrandomstring" name="email" value="" placeholder="Enter email" type="email" dataid="sh_email1" onfocus="if (this.hasAttribute('readonly')) {

    this.removeAttribute('readonly');

    // fix for mobile safari to show virtual keyboard

    this.blur();    this.focus();  }">

//input[@id='shub34']


3. value attribue 

<button value="Submit">Submit</button>

//button[@value='Submit']


4. contains() method with hyperlink 

<a href="https://selectorshub.com/shadow-dom-in-iframe/" traget="_blank">Click to practice shadow dom inside iframe scenario</a>

//a[contains(text(),'Click to practice')]


5. starts-with() method 

<span>A tool to generate manual test cases automatically TestCase Studio - <a href="https://selectorshub.com/" target="_blank">DownLoad Link</a></span>

//span[starts-with(text(),'A tool to generate')]


6. id attribue

<input id="datepicker" value="pick a date" autocomplete="off" data-default-val="pick a date" class="hasDatepicker">

//input[@id='datepicker']


7. and operator 

<input id="pass" class="selectors-input jsSelector" title="Password" spellcheck="false" autocomplete="off_anyrandomstring" name="Password" type="password" value="" placeholder="Enter Password">

//input[@id='pass' and @type='password']


8. name attribue 

<input name="company" type="text" class="form-control" placeholder="Enter your company">

//input[@name='company' and @type='text']


9. name attribue

<input name="mobile number" type="number" class="form-control" placeholder="Enter your mobile number">

//input[@name='mobile number' and @type='number']


10. child and parent 


//table[@id='resultTable']//thead//tr//child::th[2]

//input[@id='ohrmList_chkSelectAll']//parent::th


<table id="resultTable" class="table hover">

<thead>

<tr>

<th class="checkbox-col" rowspan="1"><input id="ohrmList_chkSelectAll" name="chkSelectAll" type="checkbox" value=""></th>

<th class="header" style="width: 33%;" rowspan="1"><a class="null" href="https://bit.ly/shub_training_udemy" target="_blank" rel="noopener">Username</a></th>

<th class="header" style="width: 20%;" rowspan="1"><a class="null" href="https://bit.ly/shub_training_udemy" target="_blank" rel="noopener">User Role</a></th>

<th class="header" style="width: 33%;" rowspan="1"><a class="null" href="https://bit.ly/shub_training_udemy" target="_blank" rel="noopener">Employee Name</a></th>

<th class="header" style="width: 14%;" rowspan="1"><a class="null" href="https://bit.ly/shub_training_udemy" target="_blank" rel="noopener">Status</a></th>

</tr>

</thead>

<tbody>

<tr class="usr_acn">

<td><input id="ohrmList_chkSelectRecord_25" name="chkSelectRow[]" type="checkbox" value="25"></td>

<td class="left"><a href="https://bit.ly/shub_training_udemy" target="_blank" rel="noopener">Garry.White</a></td>

<td class="left">ESS</td>

<td class="left">Garry White</td>

<td class="left">Enabled</td>

</tr>

<tr class="usr_acn">

<td><input id="ohrmList_chkSelectRecord_16" name="chkSelectRow[]" type="checkbox" value="16"></td>

<td class="left"><a href="https://bit.ly/shub_training_udemy" target="_blank" rel="noopener">Jasmine.Morgan</a></td>

<td class="left">ESS</td>

<td class="left">Jasmine Morgan</td>

<td class="left">Enabled</td>

</tr>

<tr class="plan rit">

<td><input id="ohrmList_chkSelectRecord_21" name="chkSelectRow[]" type="checkbox" value="21"></td>

<td class="left"><a href="https://bit.ly/shub_training_udemy" target="_blank" rel="noopener">Joe.Root</a></td>

<td class="left">ESS</td>

<td class="left">Joe Root</td>

<td class="left">Enabled</td>

</tr>

<tr class="usr_acn">

<td><input id="ohrmList_chkSelectRecord_2" name="chkSelectRow[]" type="checkbox" value="2"></td>

<td class="left"><a href="https://www.youtube.com/c/SelectorsHub?sub_confirmation=1" target="_blank" rel="noopener">John.Smith</a></td>

<td class="left">Admin</td>

<td class="left">John Smith</td>

<td class="left">Enabled</td>

</tr>

<tr class="plan rit">

<td><input id="ohrmList_chkSelectRecord_14" name="chkSelectRow[]" type="checkbox" value="14"></td>

<td class="left"><a href="https://www.youtube.com/c/SelectorsHub?sub_confirmation=1" target="_blank" rel="noopener">Jordan.Mathews</a></td>

<td class="left">ESS</td>

<td class="left">Jordan Mathews</td>

<td class="left">Enabled</td>

</tr>

<tr class="plan rit">

<td><input id="ohrmList_chkSelectRecord_15" name="chkSelectRow[]" type="checkbox" value="15"></td>

<td class="left"><a href="https://bit.ly/shub_training_udemy" target="_blank" rel="noopener">Kevin.Mathews</a></td>

<td class="left">ESS</td>

<td class="left">Kevin Mathews</td>

<td class="left">Enabled</td>

</tr>

</tbody>

</table>