Pradeep Mishra Pradeep Mishra - 6 months ago 21
CSS Question

How can we extract elements value if elements attribute is dynamically changing

How can we extract value by using xpth or css selector if the attribute is dynamically changed for example:

<p data-reactid=".2e46q6vkxnc.1.$0">
<b data-reactid=".2e46q6vkxnc.1.$0.0">Mark Obtain</b>
<i class="avu-full-width" data-reactid=".2e46q6vkxnc.1.$0.1">
<span data-reactid=".2e46q6vkxnc.1.$0.1.0"> </span>
<span data-reactid=".2e46q6vkxnc.1.$0.1.1">450 A+.</span>

<p data-reactid=".2e46q6vkxnc.1.$1">
<b data-reactid=".2e46q6vkxnc.1.$1.0">Student Name</b>
<i class="avu-full-width" data-reactid=".2e46q6vkxnc.1.$1.1">
<span data-reactid=".2e46q6vkxnc.1.$0.1.0"> </span>
<span data-reactid=".2e46q6vkxnc.1.$0.1.1">First Name</span>

In this case attribute of element is dynamically changing but "Mark Obtain" and "Student Name" will always be same, so is there any way or can we write if condition or some regex along with xpath expression to get "450 A+" and "First Name" values.
Please help

Answer Source

To get required values you can use below XPath expressions:

//p[b="Mark Obtain"]//span[2]/text()

to get "450 A+."


//p[b="Student Name"]//span[2]/text()

to get "First Name"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download