Skip to content
Advertisement

Selenium continue script even if element is not present

This is an example of what my code currently looks like,

JavaScript

When for instance element ID “PhoneNumber” isn’t present, the script will stop with the error code “Unable to locate element”, what needs to be added or changed in order to continue the script without abruption even if a certain element is not present?

Thanks in advance.

Advertisement

Answer

You can implement try/except block

JavaScript

or use conditional operator as below:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement