我正在尝试使用 Selenium 编写 Gmail 登录程序。我可以点击 URL,输入用户名并单击“下一步”按钮,但是当我重定向到“密码”字段页面时,我无法找到该元素。我尝试使用 by.className 进行相同的操作。以下是字段的检查代码:
<input class="whsOnd zHQkBf"
jsname="YPqjbf"
autocomplete="current-password"
spellcheck="false"
tabindex="0"
aria-label="Enter your password"
name="password"
autocapitalize="off"
autocorrect="off"
dir="ltr"
data-initial-dir="ltr"
data-initial-value=""
badinput="false"
type="password">
下面是我写的 selenium 代码:
driver.findElement(By.className("whsOnd zHQkBf")).sendKeys("Password");
我还尝试使用 Id,通过使用父级 <div id ="password"....>
, 但它没有用。
请告诉我解决方案。
最佳答案
whsOnd zHQkBf
表示该元素有两个 CSS 类 whsOnd
和 zHQkB
。因此,您将找不到任何具有名为 whsOnd zHQkBf
的类的内容。
您必须改为使用 CSS 选择器来查找具有多个类的元素,如下所示:.whsOnd.zHQkBf
。但这与 google 登录页面上的多个元素匹配。使用以下 CSS 选择器 input[type='password']
会更容易。
关于java - 无法找到 Gmail 登录页面密码字段的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48096811/