In the following HTML code, a pop-up is generated to add a product. I am looking for an XPath or CSS selector that works in Selenium and allows me to click on the "add" button to add a new product.
I have tried using the XPath //div[18]/div[2]/div/button, which only works for one session. When the browser is closed and reopened, the above XPath no longer works. So, how can we write an XPath that does not require specifying div[number] like in the case of div[18]?
<div style="height: auto; min-height: 104px; width: auto;" class="dialog ui-dialog-content ui-widget-content">
<fieldset><legend>search</legend>
<div id="nameorids">
<input type="radio">name
<input type="radio">id
</fieldset>
<div style="clear: both; padding-top: 5px; float: right;"><button class="add">add</button></div></div>