Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, windows and java based applications. Get your 30 day free trial.
Discuss your Sahi Pro usage patterns, best practices, problems and solutions. Help others solve their problems and seek help from the community when needed. If you need specific support on your application, please email support @ sahipro.com
Discuss your Sahi Pro usage patterns, best practices, problems and solutions. Help others solve their problems and seek help from the community when needed. If you need specific support on your application, please email support @ sahipro.com
How to check if element exist?
ewa
Members
Hi All,
I don't know How to check if the page element 'select' or 'input' exist on page source and if not exist go forward with the scripts without errors, is it possible?
Example I have 2 Tags to distinguish:
document.getElementsByTagName('select')[0]
document.getElementsByTagName('input')[5]
I don't need values witch were put into those fields I only would like to know if they exist.
I don't know How to check if the page element 'select' or 'input' exist on page source and if not exist go forward with the scripts without errors, is it possible?
Example I have 2 Tags to distinguish:
document.getElementsByTagName('select')[0]
document.getElementsByTagName('input')[5]
I don't need values witch were put into those fields I only would like to know if they exist.
This discussion has been closed.
Comments
var $ctr = 0;
var $inputElement = document.getElementsByTagName('input');
for(var $i=0; $i < $inputElement.length; $i++)
$ctr++;
i dont know if this will be ok for you.....
if ($ctr == 0)
//if not exist just do something that does not affect script
else
// i dont know what you are going to do here.....
Try if this works: Regards,
Pankaj.
For input, you could either do
It works and It can be closed.