How to verify existence of elements in page using Selenium/Java -



How to verify existence of elements in page using Selenium/Java -

i'm trying figure out way see if element existing/not existing on page.

this have far.

however, if element not existing, exception thrown, , script stop.

could help me find improve way this?

//checking navbar links system.out.println("======================="); system.out.println("navbar link checks"); //checking web link element in nav bar if(driver.findelement(by.xpath("/html/body/div[2]/div[1]/div[1]/ul/li[1]/a"))!= null){ system.out.println("web link in navbar present"); }else{ system.out.println("web link in navbar absent"); } //checking images link element in nav bar if(driver.findelement(by.xpath("/html/body/div[2]/div[1]/div[1]/ul/li[2]/a"))!= null){ system.out.println("images link in navbar present"); }else{ system.out.println("images link in navbar absent"); } //checking news link element in nav bar if(driver.findelement(by.xpath("/html/body/div[2]/div[1]/div[1]/ul/li[3]/a"))!= null){ system.out.println("news link in navbar present"); }else{ system.out.println("news link in navbar absent"); } //checking videos link element in nav bar if(driver.findelement(by.xpath("/html/body/div[2]/div[1]/div[1]/ul/li[4]/a"))!= null){ system.out.println("videos link in navbar present"); }else{ system.out.println("news link in navbar absent"); } //checking maps link element in nav bar if(driver.findelement(by.xpath("/html/body/div[2]/div[1]/div[1]/ul/li[5]/a"))!= null){ system.out.println("maps link in navbar present"); }else{ system.out.println("maps link in navbar absent"); }

you can utilize couple of different methods. this, i'd recommend using findelements:

if(driver.findelements(by.xpath("/html/body/div[2]/div[1]/div[1]/ul/li[1]/a"))!= 0)

java selenium verify

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -