Home > OS >  How to Xpath from Form
How to Xpath from Form

Time:01-25

I have html code like:

<form  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:

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

but it doesn't work. Any idea how to do it? :)

CodePudding user response:

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')]
  •  Tags:  
  • Related