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="[{"attributes":{"attribute_pa_czas-realizacji":"24h"},"availability_html":"<p class=\"stock out-of-stock\">Brak w magazynie<\/p>\n","backorders_allowed":false,"dimensions":{"length":"","width":""}]">
I would like to extract "Brak w magazynie".
I have tried xpath:
//*[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')]