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();
//以下密码未打印在PAssword文本框中 //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");
}
}
答案 0 :(得分:1)
此XPATH应该选择gmail“密码输入”://input[@name='password']
但是您不必使用XPATH,您可以通过许多其他方式来定位输入字段。例如,我正在使用此代码(在Python中):
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.NAME, 'password'))).send_keys('my_password')
编辑: 还可以尝试将命令的顺序更改为:
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='password']")));
password.sendKeys("your_password");
因为要创建密码变量WebElement password = driver.findElement(By.xpath("//input[@name='password']"));
,然后再等待它出现在DOM上:wait.until(ExpectedConditions.elementToBeClickable(password));
答案 1 :(得分:0)
这是可行的
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");