【问题标题】:Unable to find locator selenium 3.4无法找到定位器硒 3.4
【发布时间】:2017-05-14 07:33:37
【问题描述】:

这很奇怪,我正在尝试自动化我的测试,但我做不到,我使用的是 selenium 3.4,使用的是 firefox 53。 我的测试代码没有任何问题 运行此测试后无法找到元素:#email

public class TC001_LoginWithInvalidCredentials {

WebDriver   driver ;
@BeforeTest
public void setUp(){
    System.setProperty("webdriver.gecko.driver",System.getProperty("user.dir")+"/Drivers/geckodriver.exe");
    driver = new FirefoxDriver();
    driver.get("http://automationpractice.com/index.php?");
}
@Test
public void LoginWithInvalidCredentials(){
    driver.findElement(By.xpath(".//*[@id='header']/div[2]/div/div/nav/div[1]/a")).click();
    driver.findElement(By.id("email")).sendKeys("test@gmail.com");
    driver.findElement(By.id("passwd")).sendKeys("passwrd");
    driver.findElement(By.xpath(".//*[@id='SubmitLogin']")).click();

    Assert.assertEquals(driver.findElement
            (By.xpath(".//*[@id='center_column']/div[1]/ol/li")).getText(), "Authentication failed.");

}

@AfterTest
public void endTest(){
    driver.close();

}

}

<div class="form_content clearfix">
<div class="form-group form-error">
<label for="email">Email address</label>
<input id="email" class="is_required validate account_input form-control" data-validate="isEmail" name="email" value="" type="text">
</div>
<div class="form-group">
<label for="passwd">Password</label>
<span>
<input id="passwd" class="is_required validate account_input form-control" data-validate="isPasswd" name="passwd" value="" type="password">
</span>
</div>
<p class="lost_password form-group">
<a href="http://automationpractice.com/index.php?controller=password" title="Recover your forgotten password" rel="nofollow">Forgot your password?</a>
</p>
<p class="submit">
<input class="hidden" name="back" value="my-account" type="hidden">
<button id="SubmitLogin" class="button btn btn-default button-medium" type="submit" name="SubmitLogin">

【问题讨论】:

  • 你得到了什么错误以及哪个元素?

标签: html selenium element


【解决方案1】:

尝试等到元素出现在DOM 并且可点击:

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Sign in"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("email"))).sendKeys("test@gmail.com");

【讨论】:

  • 对不起。我没有使用maven 的经验
猜你喜欢
  • 2020-07-23
  • 2019-09-30
  • 1970-01-01
  • 1970-01-01
  • 2021-03-16
  • 1970-01-01
  • 2021-05-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多