Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Xpath from Form

I have html code like:

<form class="variations_form cart" action="https://example.com/name-of-product" method="post" enctype='multipart/form-data' data-product_id="386" data-product_variations="[{&quot;attributes&quot;:{&quot;attribute_pa_czas-realizacji&quot;:&quot;24h&quot;},&quot;availability_html&quot;:&quot;&lt;p class=\&quot;stock out-of-stock\&quot;&gt;Brak w magazynie&lt;\/p&gt;\n&quot;,&quot;backorders_allowed&quot;:false,&quot;dimensions&quot;:{&quot;length&quot;:&quot;&quot;,&quot;width&quot;:&quot;&quot;}]">

I would like to extract "Brak w magazynie".

I have tried xpath:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

//*[text() = 'Brak w magazynie']

but it doesn’t work. Any idea how to do it? 🙂

>Solution :

You can use the following XPath expressions to locate this element:

//form[@class='variations_form cart']

Or

//form[@action='https://example.com/name-of-product']

Or

//form[@action='https://example.com/name-of-product' and @class='variations_form cart']

And then extract the found element text
UPD
If you want to select such elements containing Brak w magazynie in their data-product_variations attribute you can use XPath like this:

//form[@class='variations_form cart' and(contains(@data-product_variations,'Brak w magazynie')) ]

Or

//form[@action='https://example.com/name-of-product' and contains(@data-product_variations,'Brak w magazynie')]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading