- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use clickandwait in Selenium Webdriver using Java?
We can click and wait in Selenium. This can be achieved by the synchronization concept. We shall use the explicit wait condition and wait for an element to be clickable prior to the next step.
The explicit wait waits for a specified amount of time before throwing an exception. To verify if an element is clickable, we can use the expected condition elementToBeClickable.
Example
Code Implementation.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class ElementClickableWait{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); String url = "https://www.tutorialspoint.com/index.htm"; driver.get(url); // identify element and click() WebElement l=driver.findElement(By.className("mui-btn")); l.click(); // explicit wait condition WebDriverWait w = new WebDriverWait(driver,3); // elementToBeClickable condition w.until(ExpectedConditions .elementToBeClickable (By.className("s-buy"))); // get page title of next page System.out.println("Current page title:" + driver.getTitle()); driver.quit(); } }
Output
- Related Articles
- How to handle frame in Selenium WebDriver using java?
- How to select checkboxes using selenium java webdriver?
- How to perform mouseover function in Selenium WebDriver using Java?
- How to type in textbox using Selenium WebDriver with Java?
- How to scroll down using Selenium WebDriver with Java?
- How to close child browser window in Selenium WebDriver using Java?
- How to simulate Print screen button using selenium webdriver in Java?
- How to automate gmail login process using selenium webdriver in java?
- How to automate drag & drop functionality using Selenium WebDriver Java?
- How to get selected option using Selenium WebDriver with Java?
- How to handle authentication popup with Selenium WebDriver using Java?
- How to use Selenium WebDriver for Web Automation?
- How to use Selenium webdriver to click google search?
- How to scroll a specific DIV using Selenium WebDriver with Java?
- Switch tabs using Selenium WebDriver with Java.

Advertisements