>我正在尝试动手操作登录页面 使用自动化代码传递有效凭据,系统仍然出错:
登录失败。
语言:Selenium webdriver with Java on Eclipse。
我尝试过标准方式:
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驱动程序,但输出相同。
尝试在代码中添加显式等待,即仅在文本可见时才在字段中输入文本。尝试以下代码:
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
按钮
尝试使用不同的浏览器,如Firefox,chrome和opera。
-
WebDriver firefox=new FirefoxDriver()//for firefox
-
WebDriver chrome=new ChromeDriver();//for chrome.
试试看。
执行 Login.click 后会发生什么? 如果登录表单需要一些时间才能呈现(甚至 30 毫秒可能很重要),那么您应该等待!否则,驱动程序将立即尝试发送密钥凭据(即使登录表单尚未准备好获取输入数据),因此某些第一个符号可能会丢失。
附言我知道我可能会犯一些重大的语法错误,对此感到抱歉。
我想你忘记了登录过程中的一个步骤。
以下是我认为大多数登录过程的外观。
- 查找身份证盒并发送钥匙
- 查找PW盒并发送钥匙
- 找到登录按钮,然后单击/发送带有PW发送密钥的"输入密钥"。
你的看起来像这样。
- 单击登录(?
- 查找 WebElement 电子邮件添加
- 查找 WebElement 电子邮件添加 (x2) (使用不同的驱动程序调用)
- 将密钥发送到电子邮件添加
- 查找 WebElement Passwd
- 将密钥发送到密码