- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Gmail login fail using Selenium webdriver. Showing element not found for password.
We can encounter Gmail login failure while using Selenium webdriver due to the error - element not found for password. This can be fixed by the methods listed below −
Adding implicit wait - Implicit wait is applied to instruct the webdriver for polling the DOM(Document Object Model) for a specific amount of time while attempting to identify an element that is currently unavailable.
The default value of the implicit wait time is 0. Once a wait time is set, it remains applicable throughout the entire life of the webdriver object. If an implicit wait is not set and an element is still not present in DOM, an exception is thrown.
Syntax
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Here, a wait time of five seconds is applied to the webdriver object.
Adding explicit wait - Explicit wait is applied to instruct the webdriver to wait for a specific condition before moving to the other steps in the automation script.
The explicit wait is implemented using the WebDriverWait class along with expected_conditions. The expected_conditions class has a group of prebuilt conditions to be used along with the WebDriverWait class.
Here, we can add the expected condition visibilityOfElementLocated for the element not found error for the password field in Gmail.
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.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.Wait; import org.openqa.selenium.support.ui.WebDriverWait; public class FirstAssign{ public static void main(String[] args){ System.setProperty("webdriver.chrome.driver", "chromedriver"); WebDriver driver = new ChromeDriver(); try{ //implicit wait of 15 seconds driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //application launch driver.get("http://www.gmail.com"); WebElement e = driver.findElement (By.xpath("//input[@type = 'email']")); e.sendKeys("abc@gmail.com"); WebElement n = driver.findElement (By.xpath("//button[@type = 'button']")); n.click(); //explicit wait WebDriverWait wait = new WebDriverWait(driver, 10); WebElement m = wait.until( ExpectedConditions.visibilityOfElementLocated (By.xpath("//input[@type = 'email']"))); driver.findElement(By.xpath ("//input[@type = 'email']")).sendKeys("1234"); n.click(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
- Related Articles
- How to automate gmail login process using selenium webdriver in java?
- Test if element is present using Selenium WebDriver?
- Test if an element is focused using Selenium Webdriver.
- Check that the element is clickable or not in Selenium WebDriver
- How to scroll to element with Selenium WebDriver using C#?
- Handle Firefox Not Responding While Using Selenium WebDriver With Python?
- sendKeys() not working in Selenium Webdriver
- How to check URL for 404 using Selenium WebDriver?
- How to automate Calendar using Selenium WebDriver for Testing?
- Which exception is raised when an element is not found in an HTML DOM using XPath in Selenium?
- Find elements using Selenium WebDriver?
- Finding an element in a sub-element in Selenium Webdriver.
- How to verify an attribute is present in an element using Selenium WebDriver?
- How do you click on an element which is hidden using Selenium WebDriver?
- Reading JavaScript variables using Selenium WebDriver.
