我的Web驱动程序是最新版本,我的代码也具有Thread.sleep,但是我无法登录该页面。
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
WebDriver driver;
@BeforeTest
public void navegador() throws InterruptedException {
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\chromedriver.exe");
Thread.sleep(1000);
driver = new ChromeDriver();
Thread.sleep(2000);
driver.manage().window().maximize();
Thread.sleep(3000);
}
@Test
public void f() throws InterruptedException {
driver.get("somewebpage");
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
Thread.sleep(3000);
driver.findElement(By.partialLinkText("LOGIN")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("/html/body/div[1]/div[2]/form/div[1]/input")).sendKeys("myemail");
Thread.sleep(2000);
driver.findElement(By.xpath("/html/body/div[1]/div[2]/form/div[2]/input")).sendKeys("mypassword");
Thread.sleep(2000);
driver.findElement(By.xpath("/html/body/div[1]/div[2]/form/div[3]/div[2]/button")).sendKeys(Keys.ENTER);
Thread.sleep(5000);
}
@AfterTest
public void cierre() {
driver.quit();
}
}
该网页向我发送了以下消息:“这些凭据与我们的记录不匹配。” 但是,当我手动进行操作时,该页面使我可以访问家。
我无法从登录页面通过,建议?
答案 0 :(得分:0)
也许您可以尝试检查测试是否在调试模式下工作。 如果测试仍无法在调试模式下运行。然后尝试通过脚本发送后同时获取用户名和密码字段的值,并检查其是否像手动操作一样正确。
仍然失败,请分享html代码。