webdriver-Timeout and wait __web

Source: Internet
Author: User
Import Java.util.concurrent.TimeUnit;
Import Org.openqa.selenium.By;
Import Org.openqa.selenium.WebDriver;
Import Org.openqa.selenium.firefox.FirefoxDriver;


public class Selenium_timeout
{
Timeout and wait, implicitlywait, object recognition timeout, pageloadtimeout. Page load Timeout

Static Webdriver driver=new firefoxdriver ();
public static void Main (string[] args) throws Exception
{

Global settings, setting timeout for recognition of each object in code
Driver.manage (). Timeouts (). implicitlywait (Timeunit.seconds);
Global settings, setting timeout for loading per page in code
Driver.manage (). Timeouts (). Pageloadtimeout (Timeunit.seconds);

Driver.get ("http://www.baidu.com/");//Open Baidu Home page timeout of 30 seconds
Driver.findelement (By.id ("kw")). SendKeys ("Selenium"); Home page Baidu search box timeout time is 30 seconds
Driver.findelement (By.id ("su")). Click ()//Identify Baidu button timeout of 30 seconds

Selenium_timeout.opensetlink ();
}

public static void Opensetlink () throws Exception
{
Call the Waitfortime method if the recognition timeout is only for a single object
Selenium_timeout.waitfortime (By.linktext ("Settings"));
Driver.findelement (By.linktext ("Settings")). Click ();
}

Timeout method for Page object recognition
public static void Waitfortime (by) throws exception{
for (int second=1;second<=30;second++)
{
Try
{
Driver.findelement (by);
Break
}
catch (Exception e)
{
E.printstacktrace ();
}
}
Thread.Sleep (1000);
}
}

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.