package Login;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Login
{
public static void main(String[] args) throws Exception
{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Teknomines-5\\Downloads\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com/intl/en-GB/gmail/about/");
//Thread.sleep(5000);
driver.findElement(By.xpath("/html/body/nav/div/a[2]")).click();
driver.findElement(By.xpath("//*[@id=\"identifierId\"]")).sendKeys("Pratik.modh24@gmail.com");
driver.findElement(By.xpath("//*[@id=\"identifierNext\"]")).click();
//Below Code password not print on PAssword textbox
//driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[1]/div/form/content/section/div/content/div[1]/div/div[1]")).sendKeys("123");
//driver.findElement(By.className("whsOnd zHQkBf")).sendKeys("123");
//driver.findElement(By.id("Passwd")).sendKeys("test123");
//driver.findElement(By.name("password")).sendKeys("123");
//driver.findElement(By.xpath(".//*[@id='Passwd']")).sendKeys("123456789");
//driver.findElement(By.cssSelector("#password > div:nth-child(1)")).sendKeys("123");
//driver.findElement(By.xpath("//INPUT[@name='password']")).sendKeys("******");
//driver.findElement(By.xpath("//INPUT[@type='password']/self::INPUT")).sendKeys("***");
//driver.findElement(By.xpath("(//DIV[@class='aCsJod oJeWuf'])[1]")).sendKeys("123456");
WebElement password = driver.findElement(By.xpath("//input[@name='password']"));
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(password));
password.sendKeys("your_password");
}
}
Asked
Active
Viewed 1,033 times
0
2 Answers
1
This XPATH should select gmail "password input": //input[@name='password']
But you don't have to use XPATH, you can target the input field by lot of other ways. For instance I am using this (in Python):
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.NAME, 'password'))).send_keys('my_password')
EDIT: Also try changing the order of your commands to:
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='password']")));
password.sendKeys("your_password");
because you are creating the password variable WebElement password = driver.findElement(By.xpath("//input[@name='password']")); before you wait for it to appear on DOM: wait.until(ExpectedConditions.elementToBeClickable(password));
Miro
- 49
- 9
-
i also try but not work, See link https://www.useloom.com/share/5faac64ffafa4ede81d2f9d1246a790c – Pratik Aug 30 '18 at 12:03
-
I have edited my answer, please see the new suggestion. – Miro Aug 30 '18 at 12:06
0
this is working one
driver.manage().window().maximize();
driver.get("https://www.google.com/intl/en-GB/gmail/about/");
driver.findElement(By.xpath("/html/body/nav/div/a[2]")).click();
driver.findElement(By.xpath("//*[@id=\"identifierId\"]")).sendKeys("Pratik.modh24@gmail.com");
driver.findElement(By.xpath("//*[@id=\"identifierNext\"]/content/span")).click();
WebElement password = driver.findElement(By.name("password"));
password.sendKeys("your_password");
Error Hunter
- 1,354
- 3
- 13
- 35