尝试将隐式等待时间设置为大约10秒,然后再将该元素查找为:-
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);driver.findElement(By.id("Passwd")).sendKeys("yourPassword");driver.findElement(By.id("signIn")).click();或设置一个明确的等待。显式等待是您定义的代码,用于等待特定条件发生后再继续执行代码。您的情况就是密码输入字段的可见性。
WebDriverWait wait = new WebDriverWait(driver, 10);WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("Passwd")));element.sendKeys("yourPassword");//Now click on sign in button driver.findElement(By.id("signIn")).click();//next pageExplanation: The reason selenium can’t find the element is because the
idof the password input field is initially
Passwd-hidden. After you click
on the “Next” button, Google first verifies the email address entered and then
shows the password input field (by changing the id from
Passwd-hiddento
Passwd). So, when the password field is still hidden (i.e. Google is still
verifying the email id), your webdriver starts searching for the password
input field with id
Passwdwhich is still hidden. And hence, you should wait
until it becomes visible.



