0

我正在尝试登录页面使用自动化代码传递有效凭据,仍然系统给出错误:

登录失败。

语言:在 Eclipse 上使用 Java 的 Selenium webdriver。

我尝试过标准方式:

WebElement Login = driver.findElement(By.className("flex-signup"));
Login.click();
WebElement EmailAdd = driver.findElement(By.id("emailAddress")); 

WebElement EmailAdd = Driver.findElement(By.id("****"));
EmailAdd.sendKeys("************");
WebElement Passwd = driver.findElement(By.id("****"));
Passwd.sendKeys("*******");

我还使用了另一种方式,JavaScript 驱动程序。但这也不适用于应用程序。

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].value='*************';" ,****);
jse.executeScript("document.getElementById('****').value='**********';");
WebElement BLogin = driver.findElement(By.className("ladda-label"));
jse.executeScript("arguments[0].click();", BLogin);

应用程序在 JavaScript 中,所以我也使用了 JavaScript 驱动程序,但输出相同。

4

4 回答 4

1

尝试在代码中添加显式等待,即仅在字段可见时在字段中输入文本。试试下面的代码:

WebDriverWait wait=new WebDriverWait(driver, 20);
WebElement Login = driver.findElement(By.className("flex-signup"));
Login.click();
//WebElement EmailAdd = driver.findElement(By.id("emailAddress")); 
//WebElement EmailAdd = Driver.findElement(By.id("****"));
WebElement EmailAdd=wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("****"));

EmailAdd.sendKeys("************");

WebElement Passwd = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("****"));
Passwd.sendKeys("*******");

然后点击Login按钮

于 2019-08-13T14:21:06.997 回答
0

Login.click 执行后会发生什么?如果登录表单需要一些时间来呈现(甚至 30 毫秒可能很重要),那么您应该等待!否则驱动程序将立即尝试发送密钥凭据(即使登录表单尚未准备好获取输入数据),因此某些第一个符号可能会丢失。

PS我知道我可能会犯一些重大的语法错误,对此感到抱歉。

于 2019-08-13T08:57:01.893 回答
0

我认为您忘记了登录过程中的一个步骤。

以下是我认为大多数登录过程的外观。

  1. 查找 ID 框并发送密钥
  2. 查找 PW Box 并发送密钥
  3. 找到登录按钮并单击/发送带有 PW 发送密钥的“输入密钥”。

你的看起来像这样。

  1. 点击登录(?)
  2. 查找 WebElement 电子邮件添加
  3. 查找 WebElement EmailAdd (x2)(使用不同的驱动程序调用)
  4. 将密钥发送到电子邮件添加
  5. 查找 WebElement 密码
  6. 将密钥发送到 Passwd
于 2019-08-13T18:05:42.273 回答
0

尝试不同的浏览器,如 Firefox、chrome 和 opera。

  • WebDriver firefox=new FirefoxDriver() //for firefox

  • WebDriver chrome=new ChromeDriver();//for chrome.

试试看。

于 2019-08-13T07:09:00.300 回答