Saturday, 15 March 2014

how to verify object using xpath if object is invisible in selenium webdriver java -



how to verify object using xpath if object is invisible in selenium webdriver java -

how can verify invisible objects gets enabled on wrong info entry (label before textbox eg: login scenario) using xpath in selenium webdriver.

if labels display error message (e.g. username label , password label),i able verify , capture text (error messages). xpath username: .//[@id='loginform']/p[1]/p/label xpath password: .//[@id='loginform']/p[2]/p/label

but if come in right username,webdriver go on searching xpath username(.//*[@id='loginform']/p[1]/p/label) , not respond.

html visible if error appears: label class="error" generated="true" for="username" label class="error" generated="true" for="passwordfield

can help me this?

use webdriverwait:

webdriverwait waiting = new webdriverwait(driver, 15, 100); waiting.until(expectedconditions.invisibilityofelementlocated(by.xpath("//*[@id='loginform']/p[1]/p/label")));

the above create web driver wait object wait 15 sec (checking status every 100ms) element become invisible. pass straight away if element invisible when line of code triggered.

edit based upon comments below

if trying find out if element exists of not can do:

list<webelement> labelcount = driver.findelements(by.xpath("//*[@id='loginform']/p[1]/p/label"));

if size 0 label isn't there, else there, like:

if(labelcount.size() == 0){ //get tab text } else { //enter sec field info }

java selenium-webdriver

No comments:

Post a Comment