Tag: Select exists false path get print. com htm operation
These days in the process of writing automation met the need to first click the other, and then need to wait for a while elements. I tried several ways yesterday. The first use of the Isdispaly () method, but has been an error.
That's the way it is. I was later printed on the next line of sleep and found out if the program had exited. Well, change to wait for 30s (implicit wait and explicit use), or not.
Okay, here's the crap. The solution method.
First, write a function that checks whether an element exists. This actually exists in my project. The ancestors planted trees posterity. or refer to this page. http://uniquepig.iteye.com/blog/1703553
public static boolean Iselementexsit (Webdriver Driver,by selector) { boolean result=false ; try {driver.findelement (selector ); Result =true ; catch (Exception ex) { Logger.error (Ex.getmessage ()); Result =false ; return result; }
Then happily write a for loop just fine.
1 for(inti = 0; I < 30; i++) {2String a= "/html/body/div[1]//p";3 Booleanflag=iselementexsit (Driver, By.xpath (a));4Logger.log ("+flag");//Print whether the element is found5 if(flag) {6String re =Driver.findelement (By.xpath (a)). GetText ();7 Break;8 9 }TenSleeper.sleep (1); One}
Actions for elements that need to wait for some time after a click