How can I do to verify or assert an alert with a message that contains a variable in this text?
For example, I have to capture a alert with this message: Answer numbe
to simulate the click in the buton OK you could use command assertAlert - Getting an alert has the same effect as manually clicking OK. If an alert is generated but you do not consume it with getAlert, the next Selenium action will fail.
You could use getAlert:
"Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts."