Actions for elements that need to wait for some time after a click

Source: Internet
Author: User
Tags xpath

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.